How to change RGB value without changing index value of an image?

3 次查看(过去 30 天)
Hi,
I have NxM matrix, I want to plot iamge of it and the change specific rgb value without changing index value. How can I do that? I add a sample image.
For example pixel [26,28] and Index 87 have meaningful value for me. I want to change color of this pixel to red without changing index value 87.
Thanks for your help.

采纳的回答

Walter Roberson
Walter Roberson 2023-2-15
You would have to change the active colormap at index 87 to be red, which would change all other locations with the same value.
Alternatives:
You could create an overlay image the same size with AlphaData 0.0 except at locations that you wish to recolor. You will probably want to use an rgb image to contain the additional color. You would turn hittest off on the overlay image so that the data cursor would report for the original image.
Or you could change the data cursor callback function so that it outputs your values of interest even though you have changed the image data
I would have to check to see if image objects are eligible to use the newer datatip templates
  6 个评论

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2023-2-19
% Make sample data.
rows = 10;
columns = 40;
indexedImage = randi(255, [rows, columns], 'uint8');
% Show original image.
subplot(2, 1, 1);
imshow(indexedImage, [])
% Create mask of where the image is exactly 87.
mask = indexedImage == 87;
% overlay the mask onto the original image, creating an RGB image.
rgbImage = imoverlay(indexedImage, mask, 'r');
% Display the overlay image.
subplot(2, 1, 2);
imshow(rgbImage)
  3 个评论
Image Analyst
Image Analyst 2023-2-20
They said "I want to change color of this pixel to red without changing index value 87." Walter gave one way - to apply a colormap. I gave an alternative way - using an overlay. I did not change the original pixel value. I just created a new image with red in those pixel locations. imoverlay is a function worth knowing about. The original poster can use the method they like best.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by