首先说一下,我只是非计算机专业的大二学生,没有系统性的学习过相关知识,都是靠社区大佬的博客一点点找着写出来,第一次写出一个像样的程序,还请各位多多包涵,如果有错误、需要优化的地方,还请多多指教。
先来说一下这个程序的基本功能。
一,左侧调色板
左侧调色板:需要在rgb三个模式下形成不同的色板,而且不是单向的渐变,我选择计算每个点的像素值然后用imshow显示出来,引用全局变量‘colormode’判断当前颜色模式。
axes(handles.axes2);
cla reset;
space=handles.spacecode;
switch space
case 1
sr=get(handles.rgb_r,'string');
r=str2num(sr);
A=zeros(256,256,3,"uint8");
for m=1:1:256
for n=1:1:256
A(m,n,1)=r;
A(m,n,2)=256-m;
A(m,n,3)=n;
end
end
imshow(A);
hold on;
case 2
sg=get(handles.rgb_g,'string');
g=str2num(sg);
A=zeros(256,256,3,"uint8");
for m=1:1:256
for n=1:1:256
A(m,n,1)=256-m;
A(m,n,2)=g;
A(m,n,3)=n;
end
end
imshow(A);
hold on;
case 3
sb=get(handles.rgb_b,'string');
b=str2num(sb);
A=zeros(256,256,3,"uint8");
for m=1:1:256
for n=1:1:256
A(m,n,1)=n;
A(m,n,2)=256-m;
A(m,n,3)=b;
end
end
imshow(A);
hold on;
end
左侧调色板的colorbar,为了满足可以点击然后得到相应值的功能,我没有用colorbar直接生成,而是单独生成了一个axes,根据不同颜色模式转换并等待bottoncall返回y轴的值。
生成字段:
axes(handles.axes1);
set(gca,'XColor',get(gca,'Color')) ;
set(gca,'XTickLabel',[]);
map=zeros(256,3);
space=handles.spacecode;
switch space
case 1
for i=0:1:255
map(i+1,1)=i/255;
end
for i=1:1:3
map(r+1,i)=1;
end
case 2
for i=0:1:255
map(i+1,2)=i/255;
end
for i=1:1:3
map(g+1,i)=1;
end
case 3
for i=0:1:255
map(i+1,3)=i/255;
end
for i=1:1:3
map(b+1,i)=1;
end
end
colormap(map);
x = [0 1 1 0];
y = [0 0 255 255];
c = [0; 0; 768; 768];
patch(x,y,c);
hold on;
buttoncall:
axes(handles.axes1);
pos = get(handles.axes1,'Currentpoint');
m=pos(1,2);
m=fix(m);
if m>255
m=255;
end
if m<0
m=0;
end
space=handles.spacecode;
右侧颜色各个参数,在callback里面分别计算显示。
二,均匀调色板
均匀调色板:
因为需要点击一个色块使得切换成当前色块的颜色到新的颜色中,所以axes绘图然后调成点击的坐标然后输出值这种方式会很麻烦,我的想法是直接创建25个botton,通过改变它的backgroundcolor实现均匀调色的目的。
生成过程:
space=handles.spacecode;
switch space
case 1
set(handles.t1_1,'backgroundcolor',[r/255 (g+2*tap)/255 (b-2*tap)/255]);
set(handles.t1_2,'backgroundcolor',[r/255 (g+2*tap)/255 (b-tap)/255]);
set(handles.t1_3,'backgroundcolor',[r/255 (g+2*tap)/255 b/255]);
set(handles.t1_4,'backgroundcolor',[r/255 (g+2*tap)/255 (b+tap)/255]);
set(handles.t1_5,'backgroundcolor',[r/255 (g+2*tap)/255 (b+2*tap)/255]);
set(handles.t2_1,'backgroundcolor',[r/255 (g+tap)/255 (b-2*tap)/255]);
set(handles.t2_2,'backgroundcolor',[r/255 (g+tap)/255 (b-tap)/255]);
set(handles.t2_3,'backgroundcolor',[r/255 (g+tap)/255 b/255]);
set(handles.t2_4,'backgroundcolor',[r/255 (g+tap)/255 (b+tap)/255]);
set(handles.t2_5,'backgroundcolor',[r/255 (g+tap)/255 (b+2*tap)/255]);
set(handles.t3_1,'backgroundcolor',[r/255 g/255 (b-2*tap)/255]);
set(handles.t3_