Home > chronux_1_15 > spikesort > utility > datatools > cmplx2rgb.m

cmplx2rgb

PURPOSE ^

CMPLX2RGB Convert complex matrix to an imageable RGB form.

SYNOPSIS ^

function rgbdata = cmplx2rgb(cmplxdata, logmag)

DESCRIPTION ^

CMPLX2RGB         Convert complex matrix to an imageable RGB form.
   RGBDATA = CMPLX2RGB(CMPLXDATA) converts the [M x N] CMPLXDATA to an
   [M x N x 3] truecolor matrix in RGB color coordinates.  The mapping
   goes through HSB space, where the hue is determined by the data phase,
   the brightness is determined by the data magnitude, and the saturation
   is 0.6.  The RGB values are scaled to be between 0 and 1 (set to 1 if
   all data points have the same magnitude).

   RGBDATA = CMPLX2RGB(CMPLXDATA, 'log') uses the log of the data
   magnitude to determine brightness.  Zero values are set to NaN.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function rgbdata = cmplx2rgb(cmplxdata, logmag)
0002 %CMPLX2RGB         Convert complex matrix to an imageable RGB form.
0003 %   RGBDATA = CMPLX2RGB(CMPLXDATA) converts the [M x N] CMPLXDATA to an
0004 %   [M x N x 3] truecolor matrix in RGB color coordinates.  The mapping
0005 %   goes through HSB space, where the hue is determined by the data phase,
0006 %   the brightness is determined by the data magnitude, and the saturation
0007 %   is 0.6.  The RGB values are scaled to be between 0 and 1 (set to 1 if
0008 %   all data points have the same magnitude).
0009 %
0010 %   RGBDATA = CMPLX2RGB(CMPLXDATA, 'log') uses the log of the data
0011 %   magnitude to determine brightness.  Zero values are set to NaN.
0012 
0013 % Argument checking.
0014 if (nargin < 2)
0015     logmag = 0;
0016 elseif (strcmp(logmag, 'log'))
0017     logmag = 1;
0018 else
0019     error('Unknown argument.');
0020 end
0021 
0022 % Compute amplitude and phase.
0023 amplitude = abs(cmplxdata);
0024 phase = angle(cmplxdata) + pi;   % shift from [-Pi, Pi] to [0, 2*Pi].
0025 if (logmag)
0026     old = warning('off');
0027     amplitude = log10(amplitude);
0028     amplitude(isinf(amplitude)) = NaN;
0029     warning(old);
0030 end
0031 ampmin = min(amplitude(:));
0032 ampmax = max(amplitude(:));
0033 
0034 % Construct HSV color representation.
0035 hsvdata = zeros([size(cmplxdata) 1]);
0036 hsvdata(:,:,1) = phase / (2 * pi);
0037 hsvdata(:,:,2) = 0.6;
0038 if (abs(ampmax-ampmin) > 2*eps)   % must have variation above roundoff error
0039     hsvdata(:,:,3) = (amplitude - ampmin) ./ (ampmax - ampmin);
0040 else
0041     hsvdata(:,:,3) = 1;
0042 end
0043 
0044 % Finally, convert HSV to RGB.
0045 rgbdata = hsv2rgb(hsvdata);

Generated on Tue 15-Aug-2006 22:51:57 by m2html © 2003