フィルターのクリア

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

1 回表示 (過去 30 日間)
Emre Doruk
Emre Doruk 2023 年 2 月 15 日
コメント済み: Emre Doruk 2023 年 2 月 20 日
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 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 17 日
Nice idea to use an underlay instead.
Emre Doruk
Emre Doruk 2023 年 2 月 20 日
Thanks for your help.Your ideas was very helpful to understand concept.

サインインしてコメントする。

その他の回答 (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.
Emre Doruk
Emre Doruk 2023 年 2 月 20 日
Thanks for your help.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by