Giving specific pixels a certain colour

筅森魡賤 提交于 2019-12-13 04:38:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!