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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 15 Feb. 2023
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 Kommentare
Walter Roberson
Walter Roberson am 17 Feb. 2023
Nice idea to use an underlay instead.
Emre Doruk
Emre Doruk am 20 Feb. 2023
Thanks for your help.Your ideas was very helpful to understand concept.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 19 Feb. 2023
% 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 Kommentare
Image Analyst
Image Analyst am 20 Feb. 2023
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Modify Image Colors finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by