📄 colorview.m
字号:
brighten(.5);
return;
end
if( strcmp(action,'darken') )
brighten(-.5);
return;
end
if( strcmp(action,'install') )
h=get(gcf,'UserData');
% get the figure
hfigure=h(11);
% get the image handle
himage = get(h(1),'userdata');
% get the axes
haxes=get(hfigure,'CurrentAxes'); %axes of the image
hax=h(10);% axes of the fake grid
% get the new min & max from the sliders
hcmin=h(4);
hcmax=h(2);
valmin = get(hcmin,'Value');
valmax = get(hcmax,'value');
% get the colormap from the fake grid
clrmap = get(gcf,'colormap');
% rescale the image data
n=length(clrmap);
for k=1:length(himage)
% get the image data
imagedata = get(himage(k),'cdata');
% scale the data into the range of the colormap
ind=~isnan(imagedata);
dmax=max(max(imagedata(ind)));
dmin=min(min(imagedata(ind)));
imagedata = (n-1)*(imagedata-dmin)/(dmax-dmin)+1;
% scale data into the range determined by the sliders
imagedata = (n-1)*(imagedata-valmin)/(valmax-valmin)+1;
% install the image data
%hax=get(himage(k),'parent');
%xdir=get(hax,'xdir');
%ydir=get(hax,'ydir');
set(himage(k),'cdata',imagedata);
%set(hax,'xdir',xdir,'ydir',ydir);
end
% install the colormap
set(hfigure,'ColorMap',clrmap);
%set(hax,'xdir',xdir,'ydir',ydir);
return;
end
if( strcmp(action,'autoscale') )
h=get(gcf,'UserData');
% get the sliders and set them to maximum
hcmin = h(4);
hcmax= h(2);
val = get(hcmin,'min');
set(hcmin,'value',val);
val = get(hcmax,'max');
set(hcmax,'value',val);
% call the slider refresh
colorview('cmin');
% install
% colorview('install');
return;
end
if( strcmp(action,'dismiss') )
h = get(gcf,'userdata');
hdismiss = h(8);
dismissMode = get(hdismiss,'userdata');
if( dismissMode )
set(gcf,'visible','off');
else
close(gcf);
end
return;
end
if( strcmp(action,'maps') )
% order of maps in popup is:
%'original|hsv|gray|hot|cool|bone|copper|pink|jet|alpine'
h=get(gcf,'UserData');
hmaps=h(12);
flag = get( hmaps,'value');
if( flag == 1) % original colormap
clrmap = get(hmaps,'userdata');
colormap(clrmap);
elseif( flag == 2) % hsv colormap
colormap(hsv);
elseif( flag == 3) % gray
colormap(gray);
elseif( flag == 4 ) % hot
colormap(hot);
elseif( flag == 5) % cool
colormap(cool);
elseif( flag == 6) % bone
colormap( bone );
elseif( flag == 7) % copper
colormap(copper);
elseif( flag== 8 ) % pink
colormap(pink);
elseif( flag == 9) % jet
colormap(jet);
elseif( flag == 10) % alpine
colormap(alpine);
% the following is ineffective because contrast needs the actual amplitude
% distribution of the data in the parent window, not the fake data
% created here
% elseif( flag == 10) % contrast
% z = get(gca, 'userdata');
% colormap(contrast(z));
end
return;
end
% refresh is called by the parent display if the image has changed in order to
% give the colorfigure the new image handle
if( strcmp(action,'refresh') )
hcolorfig = datamin;
h = get(hcolorfig, 'userdata');
hcmaxLabel = h(1);
set(hcmaxLabel,'userdata',himage);
return;
end
%
% determine if its a color window
%
if(strcmp(action,'iscolor'))
htest=himage;
hfigs=figs;
hfig=0;
if( ~isempty(htest) )
ind=find(hfigs==htest);
if(isempty(ind))
h=get(htest,'userdata');
if(length(h)>0)
hkids=get(htest,'children');
ind=find(hkids==h(1));
if(~isempty(ind))
if(strcmp(get(h(1),'type'),'uicontrol'))
if(strcmp(get(h(1),'string'),'Color Max:'))
hfig=1;
end
end
end
end
end
return;
end
end
%
% delete a coloraxes in the main figure
%
if(strcmp(action,'deletecolor'))
hcax=himage;
hmasterfig=get(hcax,'parent');
hax=get(hmasterfig,'currentaxes');
pos=get(hax,'position');
set(hax,'position',[pos(1)-.05 pos(2) pos(3)+.05 pos(4)]);
delete(hcax);
return;
end
%
% make a second color axes in the main window showing
% color values
%
if(strcmp(action,'coloraxes'))
hmasterfig=himage;
hcolorfig=datamin;
if(~colorview('iscolor',hcolorfig))
hfig=[];
return;
end
h=get(hcolorfig,'userdata');
hcmaxlabel=h(1);
hcmin=h(4);
dat=get(hcmin,'userdata');
datamin=dat(1);
datamax=dat(2);
himage=get(hcmaxlabel,'userdata');
clrmap=get(hcolorfig,'colormap');
hax=get(hmasterfig,'currentaxes');
% make some data to show the colors
x=[1 2 3 4 5];
[m,n]=size(colormap);
imagedata = get(himage(1),'cdata');
ind=~isnan(imagedata);
immin = floor(min(min(imagedata(ind))));
immax = ceil(max(max(imagedata(ind))));
z = (immax:-1.:immin)';
y=linspace(datamax,datamin,length(z));
y=y';
z=z*ones(1,5);
%make an axes just to the left of the current axes
%in the masterfig
figure(hmasterfig);
pos=get(hax,'position');
haxnew=axes('position',[pos(1)-.05 pos(2) .05 pos(4)/4]);
set(hax,'position',[pos(1)+.05 pos(2) pos(3)-.05 pos(4)]);
hax=get(hmasterfig,'currentaxes');
set(hmasterfig,'currentaxes',haxnew);
%make the image plot
hgrid=image(x,flipud(y),flipud(z));
ytick = linspace(min(y),max(y),8);
fact = floor(log10(ytick(8)-ytick(1)));
fact = 10^(fact-2);
ytick = fact*floor(ytick/fact);
set(haxnew,'XTick',[],'DataAspectRatiomode','auto','ytick',ytick,...
'ydir','normal','xlabel',text(0,0,'colorscale'));
set(hcmaxlabel,'userdata',[himage hgrid]);
set(hmasterfig,'currentaxes',hax);
hfig=haxnew;
return;
end
%
% return the color scaling values
%
if(strcmp(action,'getvalues'))
hcolorfig=himage;
if( ~colorview('iscolor',hcolorfig))
hfig=[];
return;
end
h=get(hcolorfig,'userdata');
% get the new min & max from the sliders
hcmin=h(4);
hcmax=h(2);
valmin = get(hcmin,'Value');
valmax = get(hcmax,'value');
hfig=[valmin valmax];
return;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -