Home > bioelectromagnetism > eeg_colormap.m

eeg_colormap

PURPOSE ^

eeg_colormap - generates EEG/ERP colormaps for eeg_toolbox

SYNOPSIS ^

function [p] = eeg_colormap(p)

DESCRIPTION ^

 eeg_colormap - generates EEG/ERP colormaps for eeg_toolbox

   [p] = eeg_colormap(p)

   Returns a colormap matrix [LENGTH, 3] into p.colorMap.map,
   which can be used with matlab colormap command.  For example:

  [p] = eeg_colormap; colormap(p.colorMap.map);

   The p.colorMap field is a struct with the following fields:
   
   style:  'Gray'           grayscale (always linear)
           'Red/Blue'       red/blue {default}
           'Red/Blue/White' red/blue with white middle of width = WWIDTH
   exp:    Exponent {1=linear, 2=squared [default],3=cubed,etc.}.
           Higher exponents increase contrast between the extreme
           values and the middle values.
   length: size of colormap matrix {25 default}.
           If not even, it will be rounded down to nearest even number
   Cmin:   min RGB range, 0 <= RGB <=1; Cmin < Cmax {0 default}
   Cmax:   max RGB range, 0 <= RGB <=1; Cmax > Cmin {1 default}
   plot:   plot colormap, 1=plot, 0=no plot {0 default}

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [p] = eeg_colormap(p)
0002 
0003 % eeg_colormap - generates EEG/ERP colormaps for eeg_toolbox
0004 %
0005 %   [p] = eeg_colormap(p)
0006 %
0007 %   Returns a colormap matrix [LENGTH, 3] into p.colorMap.map,
0008 %   which can be used with matlab colormap command.  For example:
0009 %
0010 %  [p] = eeg_colormap; colormap(p.colorMap.map);
0011 %
0012 %   The p.colorMap field is a struct with the following fields:
0013 %
0014 %   style:  'Gray'           grayscale (always linear)
0015 %           'Red/Blue'       red/blue {default}
0016 %           'Red/Blue/White' red/blue with white middle of width = WWIDTH
0017 %   exp:    Exponent {1=linear, 2=squared [default],3=cubed,etc.}.
0018 %           Higher exponents increase contrast between the extreme
0019 %           values and the middle values.
0020 %   length: size of colormap matrix {25 default}.
0021 %           If not even, it will be rounded down to nearest even number
0022 %   Cmin:   min RGB range, 0 <= RGB <=1; Cmin < Cmax {0 default}
0023 %   Cmax:   max RGB range, 0 <= RGB <=1; Cmax > Cmin {1 default}
0024 %   plot:   plot colormap, 1=plot, 0=no plot {0 default}
0025 %
0026 
0027 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0028 
0029 % Licence:  GNU GPL, no implied or express warranties
0030 % History:  08/2001, Darren.Weber_at_radiology.ucsf.edu, created
0031 %           05/2001, Darren.Weber_at_radiology.ucsf.edu
0032 %                    - added EXP argument and changed default from
0033 %                      linear (EXP=1) to square (EXP=2).
0034 %                    - ensured that Length is an even number
0035 %                    - converted input/output to p struct
0036 %
0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0038 
0039 if ~exist('p','var'),
0040     error('EEG_COLORMAP: No input p struct, use eeg_toolbox_defaults.');
0041 else
0042     if ~isfield(p,'colorMap'), p.colorMap = []; end
0043     if ~isfield(p.colorMap,'style'),  p.colorMap.style   = 'Red/Blue/White'; end
0044     if ~isfield(p.colorMap,'exp'),    p.colorMap.exp     = 1;   end
0045     if ~isfield(p.colorMap,'Cmin'),   p.colorMap.Cmin    = 0;   end
0046     if ~isfield(p.colorMap,'Cmax'),   p.colorMap.Cmax    = 1;   end
0047     if ~isfield(p.colorMap,'plot'),   p.colorMap.plot    = 0;   end
0048 end
0049 
0050 % Ensure that Length is defined and an even number
0051 if ~isfield(p.colorMap,'length'),
0052     p.colorMap.length  = 40;
0053 else
0054     p.colorMap.length = fix(p.colorMap.length/2) * 2;
0055 end
0056 
0057 
0058 %A color map matrix may have any number of rows, but it must have
0059 %exactly 3 columns.  Each row is interpreted as a color, with the
0060 %first element specifying the intensity of red light, the second
0061 %green, and the third blue.  Color intensity can be specified on the
0062 %interval 0.0 to 1.0.
0063 
0064 switch p.colorMap.style
0065     
0066     case 'Gray'
0067         
0068         R = linspace(p.colorMap.Cmin,p.colorMap.Cmax,p.colorMap.length);
0069         Gmap = [R' R' R']; % R=G=B
0070         p.colorMap.map = Gmap;
0071         
0072     case 'Red/Blue'
0073         
0074         X = linspace(p.colorMap.Cmin,p.colorMap.Cmax,p.colorMap.length);
0075         R = X .^ p.colorMap.exp;
0076         G = R .* 0;
0077         B = fliplr(R);
0078         
0079         RBmap = [R' G' B'];
0080         p.colorMap.map = RBmap;
0081         
0082     case 'Red/Blue/White'
0083         
0084         Half = (p.colorMap.length / 2);
0085         
0086         % Calculate the required exponent min/max so that
0087         % min/max R1 below will be 0/Cmax-Cmin
0088         Expmin = 0;
0089         Expmax = (p.colorMap.Cmax - p.colorMap.Cmin) .^ ( 1 / p.colorMap.exp );
0090         
0091         % Generate an array of values from Expmin to Expmax, using
0092         % half the length of the colormap
0093         X  = linspace(Expmin,Expmax,Half);
0094         
0095         % Now raise it to the power of exp
0096         R1 = X .^ p.colorMap.exp;
0097         
0098         % Now add Cmin
0099         R1 = R1 + p.colorMap.Cmin;
0100         
0101         % Translate the curve origin to zero and
0102         % reflect it about the X axis
0103         tmp = 0 - (R1 - p.colorMap.Cmin);
0104         % Reflect it about the y axis
0105         tmp = fliplr(tmp);
0106         % Now add the Cmax value
0107         tmp = tmp + p.colorMap.Cmax;
0108         
0109         R1 = tmp(1:end-1);
0110         
0111         Cmax = ones(size(R1)) * p.colorMap.Cmax;
0112         
0113         R2 = fliplr(R1);
0114         
0115         R  = [ Cmax R2 ];   % Red array
0116         G  = [ R1 R2 ];     % Green array
0117         B  = fliplr(R);     % Blue array
0118         
0119         % Create colormap from Blue to Red
0120         Cmap = [B' G' R'];
0121         
0122         % Add the max value into the middle of the cmap to
0123         % even up the zero color point
0124         tmp1 = Cmap(1:Half-1,:);
0125         tmp2 = [p.colorMap.Cmax p.colorMap.Cmax p.colorMap.Cmax];
0126         tmp3 = Cmap(Half:end,:);
0127         Cmap = [ tmp1; tmp2; tmp3 ];
0128         
0129         p.colorMap.map = Cmap;
0130         
0131         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0132         % Add pink or white tips to this colormap
0133         Expmin = 0;
0134         Expmax = (p.colorMap.Cmax - p.colorMap.Cmin) .^ ( 1 / 20 );
0135         
0136         X = linspace(Expmin,Expmax,length(Cmap));
0137         B = X .^ 10;
0138         R = fliplr(B);
0139         % for white tips
0140         %G = B + R; Addmap = [R' G' B'];
0141         % for pink/white tips
0142         %G = X .^ 40; G = G + fliplr(G); Addmap = [R' G' B'];
0143         % for pink tips
0144         %G = X .* 0; Addmap = [R' G' B'];
0145         % yellow, cyan tips
0146         G = B + R; Addmap = [B' G' R'];
0147         
0148         Addmap = (Cmap + Addmap);
0149         
0150         index = find(Addmap > p.colorMap.Cmax);
0151         Addmap(index) = p.colorMap.Cmax;
0152         
0153         p.colorMap.map = Addmap;
0154         
0155     case 'default',
0156         
0157         p.colorMap.map = jet;
0158         
0159     otherwise
0160         
0161         % get matlab colormap
0162         % this may not work under all circumstances,
0163         % when Style is not a matlab colormap
0164         p.colorMap.map = colormap(p.colorMap.style);
0165         %R = linspace(Cmin,Cmax,Length);   B = fliplr(R);   G = zeros(size(R));
0166         %RBmap = [R' G' B'];
0167         %Map = RBmap;
0168 end
0169 
0170 
0171 % Plot colormap
0172 if (p.colorMap.plot),
0173     figure('NumberTitle','off','Name','EEG Toolbox Colormap');
0174     colormap(p.colorMap.map); rgbplot(p.colorMap.map); colorbar
0175     axis tight
0176 end
0177 
0178 return

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