Why does using ind2rgb on an image file give me non-RGB color values?
4 views (last 30 days)
Show older comments
I have an image that I have loaded into MATLAB (image1)
Then I do the following:
[IND, map] = rgb2ind(image1, 20);
image2 = ind2rgb(IND, map);
imshow(image2);
The image displays correctly with only 20 colors. However, when I look at the values for the RGB data of the image, they are all decimal values less than 1. I thought RGB values were integers from 0-255. I do not understand the data that the program is generating, but I need the values in the 0-255 range.
Any idea what is going on here and how I can fix it?
Thanks!
0 Comments
Answers (1)
Walter Roberson
on 26 Jun 2012
In MATLAB, colormaps always hold values in the range 0 to 1, and they are floating point data types. When dealing with images, MATLAB looks at the data type to determine what range of data to deal with. If you compare class(image2) to class(image1) you will see that they are different datatypes, and that is fine with MATLAB.
If you need values in the range 0-255 for other reasons, then scale the values:
image2_uint8 = uint8( image2 .* 255 );
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!