How to read the RGB value from a grayscale image (just like the data cursor does)
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Penny
le 28 Fév 2017
Réponse apportée : Image Analyst
le 1 Mar 2017
I have a DICOM image. I have read it and stored the value in variable 'I'. So, how to read the RGB value from a grayscale image (just like the data cursor does). Here is the image with the data cursor. Variable 'I' is consisted of the index values shown in the second line on the picture. I wonder whether we can read the RGB value by command just like the third value shown on the image. If yes, how to do it? Thanks a lot
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161193/image.png)
0 commentaires
Réponse acceptée
Walter Roberson
le 28 Fév 2017
cmap = colormap();
RGB = ind2rgb(YourImage, cmap);
RGB(290, 189) %notice that X is columns and Y is rows
However, if you used imshow() to display the image, then chances are that imshow decided on the colormap for you instead of using the current colormap. If so, then instead of assigning colormap() to cmap, use
cmap = gray(256);
7 commentaires
Plus de réponses (2)
Chad Greene
le 1 Mar 2017
Alternatively, I wrote a function for this a while back. It's been a while since I wrote it, so no guarantees regarding how well it works. It's called colorpicker.
0 commentaires
Image Analyst
le 1 Mar 2017
The function you want is called impixelinfo():
hp = impixelinfo();
set(hp, 'Units', 'normalized');
set(hp, 'Position', [.5, .9, .3, .05]); % Or whatever size and location you want.
This will put up a status label where you can see the x,y and RGB values as you mouse around over the image.
0 commentaires
Voir également
Catégories
En savoir plus sur Blue dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!