⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colormapsmake.m

📁 Matlab下的EEG处理程序库
💻 M
📖 第 1 页 / 共 2 页
字号:
function [cmap] = colormapsmake(bins,fighandle)

% COLORMAPSMAKE - Interactive color map maker
%
%     Usage:    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
%

% Note: the readcolormap option is not perfect. It works well if the
% colormap contains straight lines like most matlab colormaps. You can play
% with the tolerance. Also, the more nodes in an axes the slower the mouse
% handler routines will run.

% Written by Colin Humphries, Salk Institute, March 1997
%   -add lspace function (now runs under matlab 5.2) April, 1998
%   email: chumphri@uci.edu
%
% Darren.Weber@flinders.edu.au
% Sept. 2001 - renamed from makecmap to ColorMapsMake.m
%            - added help button and minor cosmetics
%            - runs on Matlab 6.0 (R12)

% $Revision: 1.2 $ $Date: 2003/03/02 03:20:43 $


nargs = nargin;


if nargs == 0
  bins = 64;
  nargs = 1;
end


if ~isstr(bins)
  
  if size(bins,2) == 3
    map = bins;
    bins = size(map,1);
    if nargs == 1
      fighandle = [];
    end
  else
    map = [];
    if nargs == 2
      if isstr(fighandle)
        fighandle = bins;
        map = get(fighandle,'Colormap');
        bins = size(map,1);
      end
    else
      fighandle = [];
    end
  end
  
  if isempty(map)
    red = [1 0;bins 1];       % default colormap
    green = [1 0;bins 1];
    blue = [1 0;bins 1];
  else
                          % Note: this routine cycles through all
                              % the data points and assigns nodes to 
                              % the points where straight lines end.
                              % This does not work well in every 
                              % occasion. If the colormap is nonlinear
                              % in many places, a lot of nodes will be
                              % assigned.
        
    for j = 1:3           % cycle through each column
      for i = 1:bins      % cycle through each row
        if i == 1         % assign the first point as the first node
          nodes(1,:) = [1 map(1,j)];
          lastnode = nodes;   % last node assigned
        elseif i == 2
          oldtempnode = [i map(2,j)]; % assigns point 2 as the test node
        else
          tempnode = [i map(i,j)];    % look at current point
          if (abs((oldtempnode(2)-lastnode(2))/(oldtempnode(1)...
                  -lastnode(1))) <= abs((tempnode(2)-lastnode(2))...
                  /(tempnode(1)-lastnode(1)))*1.01) & ...
                  (abs((oldtempnode(2)-lastnode(2))/...
                  (oldtempnode(1)-lastnode(1))) >= ...
                  abs((tempnode(2)-lastnode(2))/...
                  (tempnode(1)-lastnode(1)))*.99) % Check whether the line
                                                  % from the last node to
                                                  % tempnode and
                                                  % oldtempnode have the
                                                  % same slope.
                                                  % Tolerance is +/- 1%
                                                    
            oldtempnode = tempnode;    % if so then move oldtempnode
          else
            nodes = [nodes;oldtempnode]; % if not then assign a new
            lastnode = oldtempnode;      % node.
            oldtempnode = tempnode;
          end
        end
      end
      nodes = [nodes;bins map(bins,j)];  % the last node is the last point
      if j == 1
        red = nodes;  % get red nodes
        nodes = []; 
      elseif j == 2
        green = nodes;% get green nodes
        nodes = [];
      elseif j == 3
        blue = nodes; % get blue nodes
        nodes = [];
      end
    end
  end
  
  mcmfighandle = figure('color','k','NumberTitle','off',...
                        'menubar','none','Tag','ColorMap Editor');
  
  if isempty(fighandle)
    fighandle = mcmfighandle;
  end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set up Colormap from nodes
%   Converts each set of nodes into a discrete vector


  for i = 1:size(red,1)-1
    W = lspace(red(i,2),red(i+1,2),red(i+1,1)-red(i,1)+1);
    mapred(red(i,1):red(i+1,1)-1) = W(1:red(i+1,1)-red(i,1))';
  end
  mapred(red(i+1,1)) = red(i+1,2);
  for i = 1:size(green,1)-1
    W = lspace(green(i,2),green(i+1,2),green(i+1,1)-green(i,1)+1);
    mapgreen(green(i,1):green(i+1,1)-1) = W(1:green(i+1,1)-green(i,1))';
  end
  mapgreen(green(i+1,1)) = green(i+1,2);
  for i = 1:size(blue,1)-1
    W = lspace(blue(i,2),blue(i+1,2),blue(i+1,1)-blue(i,1)+1);
    mapblue(blue(i,1):blue(i+1,1)-1) = W(1:blue(i+1,1)-blue(i,1))';
  end
  mapblue(blue(i+1,1)) = blue(i+1,2);
  map = [mapred(:),mapgreen(:),mapblue(:)]; % get new colormap
  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set up Graphs  


  nodenum = size(red,1);
  subplot(3,2,1)                 % Red Graph
  hold on
  for i = 1:nodenum-1
    plot(red(i,1),red(i,2),'ow')
    line([red(i,1),red(i+1)],[red(i,2),red(i+1,2)],'color','r')
  end
  plot(red(nodenum,1),red(nodenum,2),'ow') 
  axis([1 red(nodenum,1) 0 1])
  redax = gca;
  set(redax,'UserData',red,'tag','r','box','on','color','k',...
      'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
      'Ytick',(0:.2:1));
  ylabel('Red','FontSize',14)


  subplot(3,2,3)                % Green Graph
  nodenum = size(green,1);
  hold on
  for i = 1:nodenum-1
    plot(green(i,1),green(i,2),'ow')
    line([green(i,1),green(i+1)],[green(i,2),green(i+1,2)],'color','g')
  end
  plot(green(nodenum,1),green(nodenum,2),'ow') 
  axis([1 green(nodenum,1) 0 1])
  greenax = gca;
  set(greenax,'UserData',green,'tag','g','box','on','color','k',...
      'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
      'YTick',(0:.2:1));
  ylabel('Green','FontSize',14)
  
  subplot(3,2,5)                % Blue Graph
  nodenum = size(blue,1);
  hold on
  for i = 1:nodenum-1
    plot(blue(i,1),blue(i,2),'ow')
    line([blue(i,1),blue(i+1)],[blue(i,2),blue(i+1,2)],'color','b')
  end
  plot(blue(nodenum,1),blue(nodenum,2),'ow') 
  axis([1 blue(nodenum,1) 0 1])
  blueax = gca;
  set(blueax,'UserData',blue,'tag','b','box','on','color','k',...
      'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
      'YTick',(0:.2:1));
  ylabel('Blue','FontSIze',14)


  colormap(map)                % Apply Colormap
  set(fighandle,'Colormap',map)
  
  transax = axes('Position',[.578 .4056 .327 .2238]); % Transfer Graph
  hold on
  trans = [1 1;bins 1];
  nodenum = 2;
  cla
  for i = 1:nodenum-1
    plot(trans(i,1),trans(i,2),'ow')
    line([trans(i,1),trans(i+1)],[trans(i,2),trans(i+1,2)],'color','y')
  end
  plot(trans(nodenum,1),trans(nodenum,2),'ow') 
  axis([1 trans(nodenum,1) 0 1])
  trans = ones(1,bins);
  title('luminance','color','w','FontSize',14)
  set(transax,'UserData',[1 1;bins 1],'tag','y','box','on','color','k',...
      'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
      'YTick',(0:.2:1))
  set(mcmfighandle,'UserData',[map,trans(:)],'tag',int2str(fighandle))


  cbax = axes('Position',[.578 .75 .327 .1072]);  % Colorbar Graph
  colorbar(cbax)
  set(cbax,'tag','cb','xcolor','w','ycolor','w',...
      'UserData',[size(red,1),0;...
                  size(green,1),0;...
                  size(blue,1),0;...
                  red;...
                  green;...
                  blue])
  
% Title axis


  hdaxes = axes('Position',[.57 .93 .327 .05],'Visible','off',...
      'tag','hd','UserData',map);
  text(.5,0,'Colormap Editor','FontSize',16,'Color','w',...
      'HorizontalAlignment','center')


% Uicontrols
  
  uicontrol('style','pushbutton','string','Reset',...
      'Units','Normalized',...
      'Position',[.6  .2 .1 .06],...
      'Callback','ColorMapsMake(''reset'');')
  
  uicontrol('style','pushbutton','string','Export',...
      'Units','Normalized',...
      'Position',[.75 .2 .1 .06],...
      'Callback','ColorMapsMake(''export'');')
  
  uicontrol('style','pushbutton','string','Close',...
      'Units','Normalized',...
      'Position',[.6  .1 .1 .06],...
      'Callback','ColorMapsMake(''close'');')
  
  uicontrol('Style','PushButton','string','Help',...
      'Units','Normalized',...
      'Position',[.75 .1 .1 .06],...
      'Callback','ColorMapsMake(''help'');')
  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set up callbacks


  set(mcmfighandle,'WindowButtonDownFcn','ColorMapsMake(''down'');')
  set(mcmfighandle,'WindowButtonUpFcn','ColorMapsMake(''up'');')
  set(mcmfighandle,'WindowButtonMotionFcn','ColorMapsMake(''motion'');')
  set(mcmfighandle,'CloseRequestFcn','ColorMapsMake(''close'');')


% End of main function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


else
  if strcmp(bins,'down')           % Mouse Button Down Handler
    figh = gcbf;
    axhandle = gca;
    lcolor = get(axhandle,'tag');  % find out what axis we are in
    if strcmp(lcolor,'cb') | strcmp(lcolor,'hd')
      return           % if colorbar or title axis then return
    end
    xlimits = get(axhandle,'Xlim');
    ylimits = get(axhandle,'Ylim');
    nodes = get(axhandle,'UserData');
    nodenum = size(nodes,1);      % get nodes
    P = get(axhandle,'CurrentPoint'); % get mouse position
    X = P(1,1);
    Y = P(1,2);
    button = get(gcbf,'SelectionType'); % get button
    if X <= xlimits(1)-xlimits(2)*.05 | X >= xlimits(2)*1.05 | ...
          Y <= ylimits(1)-ylimits(2)*.07 | Y >= ylimits(2)*1.07
      return    % if outside of axis limits then return
    end


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -