What is the relation between non-integer index and RGB values?

5 views (last 30 days)
I am trying to access the RGB values in int16 indexed images that are contained in a .mat file. For example, > load('brain.mat') I then obtain a 'brainImg' variable which is a cell
The images are contained in this cell, such that img = brainImg{1,1};
img is then int16
I can view the image (with imshow(img,[])) and with the data tip cursor, I see, for example: X = 103, Y=35, Index=265 and the R, G, B values, which are all equal to 0.247 (gray image).
I understand 265 is the row in the colormap to which that RGB value corresponds.
When doing > img2 = im2double(img) > imshow(img2,[])
and point with the data cursor to the same point (X=103,Y=35), I see that while the RGB values are the same, the index has changed and is now Index=0.5041
In fact, the new indices are from 0.50.. to 0.51...
What does this non-integer index represent?
Can I somehow access the RGB values directly? (I tried [a, map] = imread(...) but that didn't work in my case because my images are embedded in the .mat file -- Do I need to manually extract them, save them and then read them with 'imread').
I've searched and tried many things; any insight on these questions is much appreciated!!
Thank you!
  1 Comment
Surabhi k-sreenivas
Surabhi k-sreenivas on 28 Apr 2021
While using imshow the Index value and the pixel value are different. I believe that the Index value is basically recalled from the map which is not accessible in the case of uint16. Thus using the intensity or pixel values i.e. in the 2D matrix should give you the intensity.
In the case of a monochannel camera, images have the same R,G,B values.

Sign in to comment.

Accepted Answer

Mike Garrity
Mike Garrity on 3 Jul 2014
For an indexed image, the RGB values aren't actually in the MAT file. They're in the colormap of your figure. The colormap command will give you an array of the RGB values. It can also be used to change those RGB values.
Your image can have one of two different settings for its CDataMapping property. If CDataMapping='direct', then the values in your image are indices into the array that the colormap command gives you. If CDataMapping='scaled', then a scaling operation takes place so that the smallest value in the image maps to the RGB values at the beginning of the colormap and the largest value maps to the RGB values at the end of the colormap. For int16 data, the default CDataMapping is going to be 'direct'.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!