Home > chronux_2_00 > spikesort > utility > graphicstyles > saturate.m

saturate

PURPOSE ^

SATURATE Add saturation markers to a colormap.

SYNOPSIS ^

function newmap = saturate(cmap)

DESCRIPTION ^

SATURATE          Add saturation markers to a colormap.
   SATURATE with no arguments modifies the color map of the current
   figure to emphasize minimal and maximal values.  The actual change
   is chosen heuristically to contrast with the current color map.  By
   default, the maximum value is set to white and the minumum value is
   set to black.  If either extremal value in the existing colormap is
   already close (i.e., within a radius of 0.02 in RGB-space) to black or
   white, red and blue are used for the max and min values, respectively.

   NEWMAP = SATURATE retrieves the colormap from the current figure,
   adds saturation markers and returns the result without modifying the
   current figure. 

   NEWMAP = SATURATE(MAP) adds saturation markers to the colormap MAP and
   returns the altered colormap.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function newmap = saturate(cmap)
0002 %SATURATE          Add saturation markers to a colormap.
0003 %   SATURATE with no arguments modifies the color map of the current
0004 %   figure to emphasize minimal and maximal values.  The actual change
0005 %   is chosen heuristically to contrast with the current color map.  By
0006 %   default, the maximum value is set to white and the minumum value is
0007 %   set to black.  If either extremal value in the existing colormap is
0008 %   already close (i.e., within a radius of 0.02 in RGB-space) to black or
0009 %   white, red and blue are used for the max and min values, respectively.
0010 %
0011 %   NEWMAP = SATURATE retrieves the colormap from the current figure,
0012 %   adds saturation markers and returns the result without modifying the
0013 %   current figure.
0014 %
0015 %   NEWMAP = SATURATE(MAP) adds saturation markers to the colormap MAP and
0016 %   returns the altered colormap.
0017 
0018 bwcutoff = 0.02;
0019 
0020 %%%%%  Argument checking.
0021 if (nargin < 1)
0022     cmap = colormap;
0023 elseif ((size(cmap,2) ~= 3) || ~all(cmap(:)>=0) || ~all(cmap(:)<=1))
0024     error('Colormap must have 3 columns: [R,G,B] with all values in [0,1].');
0025 end
0026 
0027 %%%%%%%%%%%%%%%%%% Decide what modification to make %%%%%%%%%%%%%%%%%%
0028 over = [1 1 1];  under = [0 0 0];
0029 
0030 if    (norm(cmap(1,:)-[0 0 0])<bwcutoff   || norm(cmap(1,:)-[1 1 1])<bwcutoff ...
0031     || norm(cmap(end,:)-[0 0 0])<bwcutoff || norm(cmap(end,:)-[1 1 1])<bwcutoff)
0032     over = [1 0 0];  under = [0 0 1];
0033 end
0034 
0035 %%%%%%%%%%%%%%%%%%%% Set the colormap or return it %%%%%%%%%%%%%%%%%%%%
0036 cmap(1,:) = under;   cmap(end,:) = over;
0037 if (nargout == 0),  colormap(cmap);
0038 else                newmap = cmap;
0039 end
0040

Generated on Fri 15-Aug-2008 11:35:42 by m2html © 2003