Home > bioelectromagnetism > ColorMapsMake.m

ColorMapsMake

PURPOSE ^

colorMapsMake - Interactive color map maker

SYNOPSIS ^

function [cmap] = colormapsmake(bins,fighandle)

DESCRIPTION ^

 colorMapsMake - Interactive color map maker

     Useage:  colormapsmake
               colormapsmake(map)
               colormapsmake(map,fighandle)
               colormapsmake(bins)
               colormapsmake(bins,fighandle)
               colormapsmake(fighandle,'fig')

       bins - size of colormap (default - 64)
       map - rgb colormap (matrix)
       fighandle - figure(s) to apply colormap (optional)
       fighandle,'fig' - reads colormap from figure (fighandle)

    Nodes are displayed as circles. To move a node use mouse
       button #1. To add a node use mouse button #2. To delete use 
       button #3.

    Mouse buttons     button 1 - move    (3 button mouse)
                      button 2 - add
                      button 3 - erase

    There are four graphs. The first three corresond to the relative
       rgb values. And the fourth graph is a luminance factor
       which the rgb values are multiplied by.

     colormap = [red,green,blue] * luminance

    Reset button - resets the colormap to the original values.
    Export button - assigns the colormap to a desktop variable.
    Close button - closes the figure window.

    Runs under Matlab 5.0 through 6.0

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [cmap] = colormapsmake(bins,fighandle)
0002 
0003 % colorMapsMake - Interactive color map maker
0004 %
0005 %     Useage:  colormapsmake
0006 %               colormapsmake(map)
0007 %               colormapsmake(map,fighandle)
0008 %               colormapsmake(bins)
0009 %               colormapsmake(bins,fighandle)
0010 %               colormapsmake(fighandle,'fig')
0011 %
0012 %       bins - size of colormap (default - 64)
0013 %       map - rgb colormap (matrix)
0014 %       fighandle - figure(s) to apply colormap (optional)
0015 %       fighandle,'fig' - reads colormap from figure (fighandle)
0016 %
0017 %    Nodes are displayed as circles. To move a node use mouse
0018 %       button #1. To add a node use mouse button #2. To delete use
0019 %       button #3.
0020 %
0021 %    Mouse buttons     button 1 - move    (3 button mouse)
0022 %                      button 2 - add
0023 %                      button 3 - erase
0024 %
0025 %    There are four graphs. The first three corresond to the relative
0026 %       rgb values. And the fourth graph is a luminance factor
0027 %       which the rgb values are multiplied by.
0028 %
0029 %     colormap = [red,green,blue] * luminance
0030 %
0031 %    Reset button - resets the colormap to the original values.
0032 %    Export button - assigns the colormap to a desktop variable.
0033 %    Close button - closes the figure window.
0034 %
0035 %    Runs under Matlab 5.0 through 6.0
0036 %
0037 
0038 % Note: the readcolormap option is not perfect. It works well if the
0039 % colormap contains straight lines like most matlab colormaps. You can play
0040 % with the tolerance. Also, the more nodes in an axes the slower the mouse
0041 % handler routines will run.
0042 
0043 % Written by Colin Humphries, Salk Institute, March 1997
0044 %   -add lspace function (now runs under matlab 5.2) April, 1998
0045 %   email: chumphri@uci.edu
0046 %
0047 % Darren.Weber_at_radiology.ucsf.edu
0048 % Sept. 2001 - renamed from makecmap to colorMapsMake.m
0049 %            - added help button and minor cosmetics
0050 %            - runs on Matlab 6.0 (R12)
0051 
0052 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:24 $
0053 
0054 
0055 nargs = nargin;
0056 
0057 
0058 if nargs == 0
0059   bins = 64;
0060   nargs = 1;
0061 end
0062 
0063 
0064 if ~isstr(bins)
0065   
0066   if size(bins,2) == 3
0067     map = bins;
0068     bins = size(map,1);
0069     if nargs == 1
0070       fighandle = [];
0071     end
0072   else
0073     map = [];
0074     if nargs == 2
0075       if isstr(fighandle)
0076         fighandle = bins;
0077         map = get(fighandle,'Colormap');
0078         bins = size(map,1);
0079       end
0080     else
0081       fighandle = [];
0082     end
0083   end
0084   
0085   if isempty(map)
0086     red = [1 0;bins 1];       % default colormap
0087     green = [1 0;bins 1];
0088     blue = [1 0;bins 1];
0089   else
0090                           % Note: this routine cycles through all
0091                               % the data points and assigns nodes to
0092                               % the points where straight lines end.
0093                               % This does not work well in every
0094                               % occasion. If the colormap is nonlinear
0095                               % in many places, a lot of nodes will be
0096                               % assigned.
0097         
0098     for j = 1:3           % cycle through each column
0099       for i = 1:bins      % cycle through each row
0100         if i == 1         % assign the first point as the first node
0101           nodes(1,:) = [1 map(1,j)];
0102           lastnode = nodes;   % last node assigned
0103         elseif i == 2
0104           oldtempnode = [i map(2,j)]; % assigns point 2 as the test node
0105         else
0106           tempnode = [i map(i,j)];    % look at current point
0107           if (abs((oldtempnode(2)-lastnode(2))/(oldtempnode(1)...
0108                   -lastnode(1))) <= abs((tempnode(2)-lastnode(2))...
0109                   /(tempnode(1)-lastnode(1)))*1.01) & ...
0110                   (abs((oldtempnode(2)-lastnode(2))/...
0111                   (oldtempnode(1)-lastnode(1))) >= ...
0112                   abs((tempnode(2)-lastnode(2))/...
0113                   (tempnode(1)-lastnode(1)))*.99) % Check whether the line
0114                                                   % from the last node to
0115                                                   % tempnode and
0116                                                   % oldtempnode have the
0117                                                   % same slope.
0118                                                   % Tolerance is +/- 1%
0119                                                     
0120             oldtempnode = tempnode;    % if so then move oldtempnode
0121           else
0122             nodes = [nodes;oldtempnode]; % if not then assign a new
0123             lastnode = oldtempnode;      % node.
0124             oldtempnode = tempnode;
0125           end
0126         end
0127       end
0128       nodes = [nodes;bins map(bins,j)];  % the last node is the last point
0129       if j == 1
0130         red = nodes;  % get red nodes
0131         nodes = []; 
0132       elseif j == 2
0133         green = nodes;% get green nodes
0134         nodes = [];
0135       elseif j == 3
0136         blue = nodes; % get blue nodes
0137         nodes = [];
0138       end
0139     end
0140   end
0141   
0142   mcmfighandle = figure('color','k','NumberTitle','off',...
0143                         'menubar','none','Tag','ColorMap Editor');
0144   
0145   if isempty(fighandle)
0146     fighandle = mcmfighandle;
0147   end
0148 
0149 
0150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0151 % Set up Colormap from nodes
0152 %   Converts each set of nodes into a discrete vector
0153 
0154 
0155   for i = 1:size(red,1)-1
0156     W = lspace(red(i,2),red(i+1,2),red(i+1,1)-red(i,1)+1);
0157     mapred(red(i,1):red(i+1,1)-1) = W(1:red(i+1,1)-red(i,1))';
0158   end
0159   mapred(red(i+1,1)) = red(i+1,2);
0160   for i = 1:size(green,1)-1
0161     W = lspace(green(i,2),green(i+1,2),green(i+1,1)-green(i,1)+1);
0162     mapgreen(green(i,1):green(i+1,1)-1) = W(1:green(i+1,1)-green(i,1))';
0163   end
0164   mapgreen(green(i+1,1)) = green(i+1,2);
0165   for i = 1:size(blue,1)-1
0166     W = lspace(blue(i,2),blue(i+1,2),blue(i+1,1)-blue(i,1)+1);
0167     mapblue(blue(i,1):blue(i+1,1)-1) = W(1:blue(i+1,1)-blue(i,1))';
0168   end
0169   mapblue(blue(i+1,1)) = blue(i+1,2);
0170   map = [mapred(:),mapgreen(:),mapblue(:)]; % get new colormap
0171   
0172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0173 % Set up Graphs
0174 
0175 
0176   nodenum = size(red,1);
0177   subplot(3,2,1)                 % Red Graph
0178   hold on
0179   for i = 1:nodenum-1
0180     plot(red(i,1),red(i,2),'ow')
0181     line([red(i,1),red(i+1)],[red(i,2),red(i+1,2)],'color','r')
0182   end
0183   plot(red(nodenum,1),red(nodenum,2),'ow') 
0184   axis([1 red(nodenum,1) 0 1])
0185   redax = gca;
0186   set(redax,'UserData',red,'tag','r','box','on','color','k',...
0187       'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
0188       'Ytick',(0:.2:1));
0189   ylabel('Red','FontSize',14)
0190 
0191 
0192   subplot(3,2,3)                % Green Graph
0193   nodenum = size(green,1);
0194   hold on
0195   for i = 1:nodenum-1
0196     plot(green(i,1),green(i,2),'ow')
0197     line([green(i,1),green(i+1)],[green(i,2),green(i+1,2)],'color','g')
0198   end
0199   plot(green(nodenum,1),green(nodenum,2),'ow') 
0200   axis([1 green(nodenum,1) 0 1])
0201   greenax = gca;
0202   set(greenax,'UserData',green,'tag','g','box','on','color','k',...
0203       'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
0204       'YTick',(0:.2:1));
0205   ylabel('Green','FontSize',14)
0206   
0207   subplot(3,2,5)                % Blue Graph
0208   nodenum = size(blue,1);
0209   hold on
0210   for i = 1:nodenum-1
0211     plot(blue(i,1),blue(i,2),'ow')
0212     line([blue(i,1),blue(i+1)],[blue(i,2),blue(i+1,2)],'color','b')
0213   end
0214   plot(blue(nodenum,1),blue(nodenum,2),'ow') 
0215   axis([1 blue(nodenum,1) 0 1])
0216   blueax = gca;
0217   set(blueax,'UserData',blue,'tag','b','box','on','color','k',...
0218       'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
0219       'YTick',(0:.2:1));
0220   ylabel('Blue','FontSIze',14)
0221 
0222 
0223   colormap(map)                % Apply Colormap
0224   set(fighandle,'Colormap',map)
0225   
0226   transax = axes('Position',[.578 .4056 .327 .2238]); % Transfer Graph
0227   hold on
0228   trans = [1 1;bins 1];
0229   nodenum = 2;
0230   cla
0231   for i = 1:nodenum-1
0232     plot(trans(i,1),trans(i,2),'ow')
0233     line([trans(i,1),trans(i+1)],[trans(i,2),trans(i+1,2)],'color','y')
0234   end
0235   plot(trans(nodenum,1),trans(nodenum,2),'ow') 
0236   axis([1 trans(nodenum,1) 0 1])
0237   trans = ones(1,bins);
0238   title('luminance','color','w','FontSize',14)
0239   set(transax,'UserData',[1 1;bins 1],'tag','y','box','on','color','k',...
0240       'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
0241       'YTick',(0:.2:1))
0242   set(mcmfighandle,'UserData',[map,trans(:)],'tag',int2str(fighandle))
0243 
0244 
0245   cbax = axes('Position',[.578 .75 .327 .1072]);  % Colorbar Graph
0246   colorbar(cbax)
0247   set(cbax,'tag','cb','xcolor','w','ycolor','w',...
0248       'UserData',[size(red,1),0;...
0249                   size(green,1),0;...
0250                   size(blue,1),0;...
0251                   red;...
0252                   green;...
0253                   blue])
0254   
0255 % Title axis
0256 
0257 
0258   hdaxes = axes('Position',[.57 .93 .327 .05],'Visible','off',...
0259       'tag','hd','UserData',map);
0260   text(.5,0,'Colormap Editor','FontSize',16,'Color','w',...
0261       'HorizontalAlignment','center')
0262 
0263 
0264 % Uicontrols
0265   
0266   uicontrol('style','pushbutton','string','Reset',...
0267       'Units','Normalized',...
0268       'Position',[.6  .2 .1 .06],...
0269       'Callback','ColorMapsMake(''reset'');')
0270   
0271   uicontrol('style','pushbutton','string','Export',...
0272       'Units','Normalized',...
0273       'Position',[.75 .2 .1 .06],...
0274       'Callback','ColorMapsMake(''export'');')
0275   
0276   uicontrol('style','pushbutton','string','Close',...
0277       'Units','Normalized',...
0278       'Position',[.6  .1 .1 .06],...
0279       'Callback','ColorMapsMake(''close'');')
0280   
0281   uicontrol('Style','PushButton','string','Help',...
0282       'Units','Normalized',...
0283       'Position',[.75 .1 .1 .06],...
0284       'Callback','ColorMapsMake(''help'');')
0285   
0286 
0287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0288 % Set up callbacks
0289 
0290 
0291   set(mcmfighandle,'WindowButtonDownFcn','ColorMapsMake(''down'');')
0292   set(mcmfighandle,'WindowButtonUpFcn','ColorMapsMake(''up'');')
0293   set(mcmfighandle,'WindowButtonMotionFcn','ColorMapsMake(''motion'');')
0294   set(mcmfighandle,'CloseRequestFcn','ColorMapsMake(''close'');')
0295 
0296 
0297 % End of main function
0298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0300 
0301 
0302 else
0303   if strcmp(bins,'down')           % Mouse Button Down Handler
0304     figh = gcbf;
0305     axhandle = gca;
0306     lcolor = get(axhandle,'tag');  % find out what axis we are in
0307     if strcmp(lcolor,'cb') | strcmp(lcolor,'hd')
0308       return           % if colorbar or title axis then return
0309     end
0310     xlimits = get(axhandle,'Xlim');
0311     ylimits = get(axhandle,'Ylim');
0312     nodes = get(axhandle,'UserData');
0313     nodenum = size(nodes,1);      % get nodes
0314     P = get(axhandle,'CurrentPoint'); % get mouse position
0315     X = P(1,1);
0316     Y = P(1,2);
0317     button = get(gcbf,'SelectionType'); % get button
0318     if X <= xlimits(1)-xlimits(2)*.05 | X >= xlimits(2)*1.05 | ...
0319           Y <= ylimits(1)-ylimits(2)*.07 | Y >= ylimits(2)*1.07
0320       return    % if outside of axis limits then return
0321     end
0322 
0323 
0324     if strcmp(button,'normal')    % left mouse button
0325       global M_BUTTON_DOWN M_PNTS M_LINES M_TEXT
0326       ii = find(X > nodes(:,1));  % find node above point
0327       minnode = max(ii);
0328       ii = find(X < nodes(:,1));  % find node below point
0329       maxnode = min(ii);
0330       if (X - nodes(minnode,1)) > (nodes(maxnode,1)-X) % if closer to maxnode
0331          if maxnode == nodenum;     % if maxnode is the endnode
0332            nodes(maxnode,2) = max(min(Y,1),0);  % only move Y-position
0333          else
0334            nodes(maxnode,1) = round(X);         % move node
0335            nodes(maxnode,2) = max(min(Y,1),0);
0336          end 
0337          M_BUTTON_DOWN = maxnode;               % save what node was selected
0338       elseif (X - nodes(minnode,1)) < (nodes(maxnode,1)-X)% if closer to minnode
0339          if minnode == 1     %if firstnode
0340            nodes(minnode,2) = max(min(Y,1),0); % only move Y-position
0341          else
0342            nodes(minnode,1) = round(X);        % move node
0343            nodes(minnode,2) = max(min(Y,1),0);
0344          end
0345          M_BUTTON_DOWN = minnode;              % save what node was selected
0346       end      
0347       cla
0348       for i = 1:nodenum-1                 % Redraw axis
0349         M_PNTS(i) = plot(nodes(i,1),nodes(i,2),'ow');
0350         M_LINES(i) = line([nodes(i,1),nodes(i+1)],...
0351             [nodes(i,2),nodes(i+1,2)],'color',lcolor);
0352       end
0353       M_PNTS(i+1) = plot(nodes(nodenum,1),nodes(nodenum,2),'ow');
0354       
0355       M_TEXT = text(0,1.05,...
0356           [' ',int2str(nodes(M_BUTTON_DOWN,1)),', ',...
0357             num2str(nodes(M_BUTTON_DOWN,2),2)],...
0358           'Color','w','clipping','off',...
0359           'VerticalAlignment','bottom',...
0360           'FontSize',10);
0361       
0362       axis([1 nodes(nodenum,1) 0 1])    
0363 
0364 
0365     elseif strcmp(button,'extend')     % Middle Mouse Button
0366       global M_BUTTON_DOWN M_PNTS M_LINES M_TEXT
0367       
0368       ii = find(X > nodes(:,1));       % find node below
0369       minnode = max(ii);
0370       ii = find(X < nodes(:,1));       % find node above
0371       maxnode = min(ii);
0372       nodes = [nodes(1:minnode,:);[round(X),max(min(Y,1),0)];...
0373           nodes(maxnode:nodenum,:)];   % add node shifting those above
0374       nodenum = size(nodes,1);
0375       M_BUTTON_DOWN = minnode+1;
0376       cla
0377       for i = 1:nodenum-1              % Redraw axis
0378         M_PNTS(i) = plot(nodes(i,1),nodes(i,2),'ow');
0379         M_LINES(i) = line([nodes(i,1),nodes(i+1)],...
0380             [nodes(i,2),nodes(i+1,2)],'color',lcolor);
0381       end
0382       M_PNTS(i+1) = plot(nodes(nodenum,1),nodes(nodenum,2),'ow'); 
0383       M_TEXT = text(0,1.05,...
0384           [' ',int2str(nodes(M_BUTTON_DOWN,1)),', ',...
0385             num2str(nodes(M_BUTTON_DOWN,2),2)],...
0386           'Color','w','clipping','off',...
0387           'VerticalAlignment','bottom',...
0388           'FontSize',10);
0389       
0390       axis([1 nodes(nodenum,1) 0 1])
0391       
0392     elseif strcmp(button,'alt')          % Right Mouse Button
0393       ii = find(X > nodes(:,1));         % find node below
0394       minnode = max(ii);
0395       ii = find(X < nodes(:,1));         % find node above
0396       maxnode = min(ii);
0397       if (X - nodes(minnode,1)) > (nodes(maxnode,1)-X)    % reassign nodes
0398         if maxnode < nodenum;
0399           nodes = [nodes(1:maxnode-1,:);nodes(maxnode+1:nodenum,:)];
0400         end
0401       elseif (X - nodes(minnode,1)) < (nodes(maxnode,1)-X)
0402         if minnode > 1
0403           nodes = [nodes(1:minnode-1,:);nodes(minnode+1:nodenum,:)];
0404         end
0405       end
0406       nodenum = size(nodes,1);
0407       cla
0408       for i = 1:nodenum-1       %redraw axis
0409          plot(nodes(i,1),nodes(i,2),'ow')
0410          line([nodes(i,1),nodes(i+1)],[nodes(i,2),nodes(i+1,2)],'color',lcolor)
0411       end
0412       plot(nodes(nodenum,1),nodes(nodenum,2),'ow') 
0413       axis([1 nodes(nodenum,1) 0 1])
0414     end
0415     set(axhandle,'UserData',nodes)  % update nodes
0416 
0417 
0418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0419 
0420 
0421 elseif strcmp(bins,'up')            % Mouse Button Up Handler
0422     figh = gcbf;
0423     global M_TEXT
0424     delete(M_TEXT)
0425     clear global M_BUTTON_DOWN M_LINES M_PNTS M_TEXT % clear variables
0426     UserData = get(figh,'UserData');
0427     fighandle = str2num(get(figh,'tag')); % get figure to apply colormap
0428     axhandle = gca;
0429     nodes = get(axhandle,'UserData');    % get nodes
0430     tagval = get(axhandle,'tag');
0431     if strcmp(tagval,'cb') | strcmp(tagval,'hd')
0432       return   % if colorbar or title axis then return
0433     end
0434     for i = 1:size(nodes,1)-1
0435       W = lspace(nodes(i,2),nodes(i+1,2),nodes(i+1,1)-nodes(i,1)+1);
0436       map(nodes(i,1):nodes(i+1,1)-1) = W(1:nodes(i+1,1)-nodes(i,1))';
0437     end
0438     map(nodes(i+1,1)) = nodes(i+1,2);
0439     if strcmp(tagval,'r')
0440       UserData(:,1) = map';
0441     elseif strcmp(tagval,'g')
0442       UserData(:,2) = map';
0443     elseif strcmp(tagval,'b')
0444       UserData(:,3) = map';
0445     elseif strcmp(tagval,'y')
0446       UserData(:,4) = map';
0447     end
0448     set(figh,'UserData',UserData,'Colormap',...      % assign new colormap
0449         UserData(:,1:3).*(UserData(:,4)*ones(1,3)))
0450     if fighandle ~= figh
0451       set(fighandle,'Colormap',UserData(:,1:3).*(UserData(:,4)*ones(1,3)))
0452     end
0453    
0454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0455   elseif strcmp(bins,'motion')      % Mouse Motion Handler
0456     global M_BUTTON_DOWN M_LINES M_PNTS M_TEXT
0457     if isempty(M_BUTTON_DOWN)
0458       return     % If mouse button is not down then return
0459     end   
0460     axhandle = gca;
0461     nodes = get(gca,'UserData');
0462     tagval = get(gca,'tag');
0463     P = get(axhandle,'CurrentPoint');
0464     X = P(1,1);
0465     Y = P(1,2);
0466     nodenum = size(nodes,1);
0467     if M_BUTTON_DOWN == 1 | M_BUTTON_DOWN == nodenum; % move selected node to
0468       nodes(M_BUTTON_DOWN,2) = max(min(Y,1),0);       % new mouse position
0469     else
0470       nodes(M_BUTTON_DOWN,1) = max(nodes(M_BUTTON_DOWN-1,1), ...
0471           min(nodes(M_BUTTON_DOWN+1,1),round(X)));
0472       nodes(M_BUTTON_DOWN,2) = max(min(Y,1),0);
0473     end
0474     
0475     delete(M_PNTS(M_BUTTON_DOWN))
0476     M_PNTS(M_BUTTON_DOWN) = plot(nodes(M_BUTTON_DOWN,1),...
0477         nodes(M_BUTTON_DOWN,2),'ow');
0478     if M_BUTTON_DOWN > 1
0479       delete(M_LINES(M_BUTTON_DOWN-1))
0480       M_LINES(M_BUTTON_DOWN-1) = line([nodes(M_BUTTON_DOWN-1,1),...
0481             nodes(M_BUTTON_DOWN,1)],...
0482           [nodes(M_BUTTON_DOWN-1,2),nodes(M_BUTTON_DOWN,2)],'color',tagval);
0483     end
0484     if M_BUTTON_DOWN < nodenum
0485       delete(M_LINES(M_BUTTON_DOWN))
0486       M_LINES(M_BUTTON_DOWN) = line([nodes(M_BUTTON_DOWN,1),...
0487             nodes(M_BUTTON_DOWN+1,1)],...
0488           [nodes(M_BUTTON_DOWN,2),nodes(M_BUTTON_DOWN+1,2)],'color',tagval);
0489     end  
0490     
0491     delete(M_TEXT)
0492     M_TEXT = text(0,1.05,...
0493           [' ',int2str(nodes(M_BUTTON_DOWN,1)),', ',...
0494             num2str(nodes(M_BUTTON_DOWN,2),2)],...
0495           'Color','w','clipping','off',...
0496           'VerticalAlignment','bottom',...
0497           'FontSize',10);
0498     
0499     axis([1 nodes(nodenum,1) 0 1])
0500     set(axhandle,'UserData',nodes)
0501     
0502   elseif strcmp(bins,'export')   % export colormap to desktop
0503     fig = gcbf;
0504     pos = get(fig,'Position');
0505     figx = 400;                  % set up dialog figure
0506     figy = 200;
0507     figh = figure('Units','pixels',...
0508         'Position',...
0509         [pos(1)+pos(3)/2-figx/2 pos(2)+pos(4)/2-figy/2 figx figy],...
0510         'Resize','off','CloseRequestFcn','','menubar','none',...
0511         'numbertitle','off');
0512     uicolor = get(figh,'Color');
0513     
0514     % text uicontrol
0515     uicontrol('Style','Text','Units','Pixels',...
0516         'String','Output Colormap to Desktop Variable:',...
0517         'Position',[20 figy-40 300 22],'HorizontalAlignment','left',...
0518         'FontSize',14,'BackGroundColor',uicolor)
0519     
0520     % edit uicontrol
0521     ui1 = uicontrol('Style','Edit','Units','Pixels',...
0522         'String','cmap','FontSize',12,...
0523         'Position',[120 figy-100 150 30]);
0524     
0525     TIMESTRING = ['[OBJ1,FIGH1] = gcbo;',...
0526                   'OBJHAN = get(OBJ1,''UserData'');',...
0527                   'LAB1 = get(OBJHAN(1),''string'');',...
0528                   'DATA1 = get(OBJHAN(2),''Colormap'');',...
0529                   'eval([LAB1,'' = DATA1;'']);',...
0530                   'delete(FIGH1);',...
0531                   'clear OBJ1 FIGH1 OBJHAN DATA1 LAB1'];
0532     
0533     % OK Button
0534     uicontrol('Style','PushButton','Units','Pixels',...
0535         'String','OK','FontSize',14,...
0536         'Position',[figx/4-20 10 65 30],...
0537         'UserData',[ui1 fig],'Callback',TIMESTRING)
0538     
0539     TIMESTRING = ['[OBJ1,FIGH1] = gcbo;',...
0540                 'delete(FIGH1);',...
0541                 'clear OBJ1 FIGH1;'];
0542     
0543     % Cancel Button
0544     uicontrol('Style','PushButton','Units','Pixels',...
0545         'String','Cancel','FontSize',14,...
0546         'Position',[3*figx/4-20 10 65 30],...
0547         'Callback',TIMESTRING)
0548     
0549   elseif strcmp(bins,'help')   % Help function
0550       
0551       helpstr = sprintf(['Left Button - move RGB node\n',...
0552                          'Middle Button - add node to RGB\n',...
0553                          'Right Button - remove node (>2)\n\n',...
0554                          'Export button - assign colormap to variable']);
0555       
0556       help = helpdlg(helpstr,'ColorMap HELP');
0557       
0558       
0559   elseif strcmp(bins,'close')   % Close Request function
0560     figh = gcbf;
0561     clear global M_BUTTON_DOWN M_LINES M_PNTS M_TEXT % get rid of global vars
0562     delete(figh)
0563   
0564   elseif strcmp(bins,'reset')   % reset Colormap to original values
0565     fighandle = gcbf;
0566     obj = findobj('tag','hd','parent',fighandle);
0567     map = get(obj,'UserData');  % get original colormap stored in hd axes
0568     set(fighandle,'Colormap',map,...
0569         'UserData',[map , ones(size(map,1),1)])
0570     
0571     obj = findobj('tag','cb','parent',fighandle);
0572     nodes = get(obj,'UserData');  % get node values stored in cb axes
0573     red = nodes(4:nodes(1,1)+3,:);
0574     green = nodes(nodes(1,1)+4:nodes(1,1)+nodes(2,1)+3,:);
0575     blue = nodes(nodes(1,1)+nodes(2,1)+4:nodes(1,1)+nodes(2,1)+...
0576         nodes(3,1)+3,:);
0577     
0578     obj = findobj('tag','r','parent',fighandle);
0579     axes(obj)                         % reset colormap graphs
0580     cla
0581     nodenum = nodes(1,1);
0582     for i = 1:nodenum-1
0583       plot(red(i,1),red(i,2),'ow')
0584       line([red(i,1),red(i+1)],[red(i,2),red(i+1,2)],'color','r')
0585     end
0586     plot(red(nodenum,1),red(nodenum,2),'ow')
0587     set(obj,'UserData',red)
0588     
0589     obj = findobj('tag','g','parent',fighandle);
0590     axes(obj)
0591     cla
0592     nodenum = nodes(2,1);
0593     for i = 1:nodenum-1
0594       plot(green(i,1),green(i,2),'ow')
0595       line([green(i,1),green(i+1)],[green(i,2),green(i+1,2)],'color','g')
0596     end
0597     plot(green(nodenum,1),green(nodenum,2),'ow')
0598     set(obj,'UserData',green)
0599     
0600     obj = findobj('tag','b','parent',fighandle);
0601     axes(obj)
0602     cla
0603     nodenum = nodes(3,1);
0604     for i = 1:nodenum-1
0605       plot(blue(i,1),blue(i,2),'ow')
0606       line([blue(i,1),blue(i+1)],[blue(i,2),blue(i+1,2)],'color','b')
0607     end
0608     plot(blue(nodenum,1),blue(nodenum,2),'ow')
0609     set(obj,'UserData',blue)
0610     
0611     obj = findobj('tag','y','parent',fighandle);
0612     axes(obj)
0613     cla
0614     trans = [1 1;size(map,1) 1];
0615     nodenum = 2;
0616     for i = 1:nodenum-1
0617       plot(trans(i,1),trans(i,2),'ow')
0618       line([trans(i,1),trans(i+1)],[trans(i,2),trans(i+1,2)],'color','y')
0619     end
0620     plot(trans(nodenum,1),trans(nodenum,2),'ow') 
0621     set(obj,'UserData',trans)
0622     figh = str2num(get(fighandle,'tag'));
0623     if figh~=fighandle
0624       set(figh,'Colormap',map)
0625     end
0626   end
0627 end
0628 
0629 
0630 return
0631 
0632 
0633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0635 
0636 function out = lspace(x,y,N)
0637 % LSPACE
0638 %   Unfortunately, linspace.m changed in Matlab 5.2, and it doesn't work
0639 %   the same. The new function cannot handle the command linspace(0,0,24).
0640 %   It just returns an empty matrix.
0641 
0642 
0643 out = [x+(0:N-2)*(y-x)/(N-1) y];
0644 
0645 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003