% % hl_map = hl_color_cycle( bh, bl, br, rh, rl, rg, gh, gl, gb ) % % Generates a cyclic color map that is formed of piecewise linear color % ramps between n*pi/6 points, in [B, M, R, Y, G, C] order. % % USAGE: % % Similar to MATLAB's 'hsv': % hl_map = hl_color_cycle( 1, 0, 1, 1, 0, 1, 1, 0, 1 ); % % Similar to MATLAB's 'jet': % hl_map = hl_color_cycle( 1, 0, .5, 1, 0, .5, 1, 0, .5 ); % % % For a map closer to constant luminance than MATLAB's "hsv", % % use hv.m: % hl_map = hl_color_cycle( 1, .4, .95, .95, .35, .8, .85, .3, .8 ); % % ARGUMENTS: % % bh, bl [0,1] Blue high, low values % br [0,1] Blue-red midpoint value % rh, rl ... Red % rg % gh, gl ... Green % gr % % RETURN VALUES: % % hl_map: 256 x 3 matrix containing RGB triplets. % % Use like: % % colormap( hl_map ), % % or use normalized [0,255] grayscale values as indices into map. % See phase2hue_cycle.m for an example. % % HARDCODED: (see below 'function' statement) % % bShow: Show color cycle, plot values and approximate luminance. % % CALLS: (none) % % Called by hl.m % % % Mark Dow, May 11, 2008 % function hl_map = hl_color_cycle( bh, bl, br, rh, rl, rg, gh, gl, gb ) %%%%%%%%%%%%%%%%%%%%%%%% % Hardcoded information: bShow = false; % Show color cycle, plot values % and approximate luminance. % %%%%%%%%%%%%%%%%%%%%%%%% hl_map = zeros( 256, 3 ); for ic = 1:43 hl_map( ic, 3 ) = bh - (bh-br)*((ic-1)/(43-1)); hl_map( ic, 1 ) = bl + (br-bl)*((ic-1)/(43-1)); if bl - (gb-bl)*((ic-0)/(43-1)) > 0 hl_map( ic, 2 ) = bl - (gb-bl)*((ic-0)/(43-1)); end end for ic = 44:86 hl_map( ic, 1 ) = br + (rh-br)*((ic-43)/(86-43)); hl_map( ic, 3 ) = br - (br-rl)*((ic-43)/(86-43)); if rl - (rg-rl)*((87-ic)/(86-44)) > 0 hl_map( ic, 2 ) = rl - (rg-rl)*((87-ic)/(86-44)); end end for ic = 87:128 hl_map( ic, 1 ) = rh - (rh-rg)*((ic-87)/(128-87)); hl_map( ic, 2 ) = rl + (rg-rl)*((ic-87)/(128-87)); if rl - (br-rl)*((ic-86)/(128-87)) > 0 hl_map( ic, 3 ) = rl - (br-rl)*((ic-86)/(128-87)); end end for ic = 129:171 hl_map( ic, 2 ) = rg + (gh-rg)*((ic-128)/(171-128)); hl_map( ic, 1 ) = rg - (rg-gl)*((ic-128)/(171-128)); if gl - (gb-gl)*((172-ic)/(171-130)) > 0 hl_map( ic, 3 ) = gl - (gb-gl)*((172-ic)/(171-130)); end end for ic = 172:214 hl_map( ic, 2 ) = gh - (gh-gb)*((ic-172)/(214-172)); hl_map( ic, 3 ) = gl + (gb-gl)*((ic-172)/(214-172)); if gl - (rg-gl)*((ic-171)/(214-172)) > 0 hl_map( ic, 1 ) = gl - (rg-gl)*((ic-171)/(214-172)); end end for ic = 215:256 hl_map( ic, 3 ) = gb + (bh-gb)*((ic-214)/(256-214)); hl_map( ic, 2 ) = gb - (gb-bl)*((ic-214)/(256-214)); if bl - (br-bl)*((257-ic)/(256-215)) > 0 hl_map( ic, 1 ) = bl - (br-bl)*((257-ic)/(256-215)); end end if bShow figure; rgbplot( hl_map ) imClrBands = repmat( 1:256, 256, 1 ); figure; imshow( imClrBands, hl_map ) luminance = .3*hl_map(:,1) + .59*hl_map(:,2) + .11*hl_map(:,3); figure; plot( luminance ); end