Create colormap to represent value intervals [0 1]

16 views (last 30 days)
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!

Accepted Answer

Shunichi Kusano
Shunichi Kusano on 11 Sep 2019
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.
  5 Comments
Fiona Gong
Fiona Gong on 18 Sep 2019
That's brilliant thanks so much Shunichi, the method works really well. It looks like I need NaNs to be white rather than transparent but I'm sure I can sort this out. Thanks!!!

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!