How to change RGB value without changing index value of an image?
조회 수: 1 (최근 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1296275/image.png)
댓글 수: 0
채택된 답변
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
2023년 2월 19일
Try imoverlay
% 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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Modify Image Colors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!