rtsColorMapField.m 820 Bytes
function Result = rtsColorMapField(F, range)
%creates a color map for the field F and returns an array with
%an additional size-3 color dimension

R = zeros(size(F));
G = zeros(size(F));
B = zeros(size(F));

%if no range is specified, estimate it using min and max values
if nargin == 1
    range(1) = min(F(:));
    range(2) = max(F(:));    
end
range_size = range(2) - range(1);

num_elements = size(F(:));
for i =1:num_elements
    if(F(i) > range(1) && F(i) < range(2))
        hue_degrees = (1 - (F(i) - range(1))/range_size)*240;
        HSVval = [hue_degrees 1.0 1.0];
        RGBval = rtsHSVtoRGB(HSVval);
    else
        RGBval = [0 0 F(i)/range(1)];
    end
    R(i) = RGBval(1);
    G(i) = RGBval(2);
    B(i) = RGBval(3);
end
Result = cat(ndims(F)+1, R, G, B);
imshow(Result);