MATLAB: Create colormap to represent value intervals [0 1]

colormap editing image display

Hi all,
I have been struggling with this for a while and seriously would appreciate any help…
So I have a matrix size [192 192 10] with values between [0 1], outside of the ROI I have values of NaN. 80% of the pixel values are within [0 0.4]. I'm trying different threshold to display the matrix and would typically like the following:
NaN = White
< 0.05 = red
[0.05 0.2] = yellow
> 0.2 = green
The colormapeditor will not allow me to select exact value ie 0.05 and 0.2, instead it only fits in figures like 0.04994 and the next one is 0.05034. Is there anyway I can manually change this?
Many thanks!

Best Answer

Hi Fiona,
how about labeling image? The following code is the example.
%% image load
img = double(rgb2gray(imread('coloredChips.png'))) / 255.;
img(randperm(numel(img), round(numel(img)/100))) = NaN;
figure;
imshow(img);
%% labeling
label = zeros(size(img), 'uint8');
label(~finite(img)) = 0;
label(img < 0.05) = 1;
label(img >= 0.05 & img <= 0.2) = 2;
label(img > 0.2) = 3;
figure;
imshow(label, []); colormap(jet);
%% make colormap
map = [1 1 1; % white for 0
1 0 0; % red for 1
1 1 0; % yellow for 2
0 1 0 ]; % green for 3
%% converting to rgb image
rgb = ind2rgb(label, map);
figure;
imshow(rgb);
Hope this helps.