问题
EDIT
I have a grayscale
image which contains pixel values of 300
, which I assigned manually to pixels that hold a specific criterion.
The case is that the other values in the image are 1
and 2
. So, I will have three values now: 1
, 2
, and 300
.
In order to display the image in a meaningful way, we can use thresholding
. So, this is as for the pixels with values 1
and 2
. For the pixels with the value 300
, how can I assign it some colour to be able to discriminate it from other parts of the image.
Thanks.
回答1:
If all the values you have are 1,2,300
then a simple colormap will solve the issue. The trick is to assign the value 3
instead of 300
so the linear mapping of colormap can be used (1,2,3), for example, if your imagesc is called im
:
im(im==300)=3;
cmap=[0.2 0.2 0.2; ...
0.4 0.4 0.4; ...
1 0 0 ];
colormap(cmap);
imagesc(im);
Here I created a 3-color colormap with colors for the 3 values (1 dark gray,2 lighter gray,3 red).
回答2:
To do this without modifying your image data, you can use the AlphaData
property to make a color overlay at select locations. Given a grayscale image img
,
imshow(img, [0 2], 'InitialMag', 'fit'); hold on
red = cat(3, ones(size(img)), zeros(size(img)), zeros(size(img)));
h = imshow(red); hold off
opacity = 1.0;
set(h, 'AlphaData', opacity*double(img==300))
EDIT: If your other values are just 1 and 2, they will be very dark compared to 300, so the [0 2]
in imshow
will help with that.
来源:https://stackoverflow.com/questions/19061400/giving-specific-pixels-a-certain-colour