function J = l2cmap(m,hue) % function J = l2cmap(m,hue) % % Two-Sided Linear Color Map % L2CMAP(M) is an M-by-3 matrix % Hue, Saturation and Intensity linearly ramped from an achromatic center. % Saturation from 0.5 to 1, Intensity from 0.5 to 1 (half-scales chosen % to avoid white,black...perhaps on better screens) % Hue linearly ramped 0 to 1/3 (color components are cyclic with period % 1/3). Center hue forced to secondary color. % L2CMAP, by itself, is the same length as the current figure's % colormap. % % optional second input "hue" is the center color. For very interesting % reasons it must be on a secondary color; 'c',{'m'},'y' % % Following IBM research on human color perception: % Why Should Engineers and Scientists Be Worried About Color? % http://www.research.ibm.com/people/l/lloydt/color/color.HTM % % T.Hilmer UH % 2010.03.14 version 1 if nargin < 1 || isempty(m) m = size(get(gcf,'colormap'),1); hue = 'c'; % MUST be on primary color for linear saturation end if nargin < 2 if ischar(m) hue = m; m = size(get(gcf,'colormap'),1); else hue = 'c'; % MUST be on primary color for linear saturation end end if strcmp(hue,'c') hue = 2/3; elseif strcmp(hue,'m') hue = 1/3; elseif strcmp(hue,'y') hue = 0; else error('"hue" must be ''c'',''m'',or ''y''') end J = zeros(m,3); n = floor(m/2); if rem(m,2) % odd z = 0; % zero resolved else % even z = []; end % Hue has period 1, but the primary colors R,G,B have period 1/3. I don't % know how to describe it better, but these components are "orthogonal", % and thus Hue is best separated into thirds. Transitions across hue don't % seem visually linear to me. Simply do a colormap(hsv),colorbar. The % primary colors are flat, and the strongest gradients are across c,m,y. % Almost sinusoidal... jh = linspace(0,1/3,m); jh = jh - hue; % apply hue shift j = jh < 0; jh(j) = jh(j) + 1; j = jh >= 1; jh(j) = jh(j) - 1; % The effect of a 2-sided linear saturation is very interesting. It maps % sinusoidally to rgb, depending on /where/ the center Hue is, % soecifically, whether it maps to a primary color % It's fascinating that the visual resolution of the colormap seems "tuned" % to work if the center is on a secondary color (c,m,y), and completely out % of tune on a primary color. js = 0.5;% half or whole scale, (0 or 0.5) js = js : (1-js)/(n-1) : 1; % nice and symmetric js = [ fliplr(js) z js ]; % js = [ js z fliplr(js) ]; % js = 1; jv = 0.5;% half or whole scale jv = jv : (1-jv)/(n-1) : 1; % nice and symmetric % jv = [ fliplr(jv) z jv ]; jv = [ jv z fliplr(jv) ]; % jv = 1; % HSV ramps: J(:,1) = jh; % HUE J(:,2) = js; % SATURATION J(:,3) = jv; % INTENSITY J = hsv2rgb(J);