need a grayscale non-indexed image
Show older comments
Hi all!
I'm trying to convert some images to gray scale.
I first used rgb2gray(); But while checking results using info=iminfo(image_name) I found that info.ColorType='indexed'
So I tried I=ind2gray(image_name,map) where map was obtained from info.Colormap but I got I=0
My guess is that I put the wrong colormap. What is the right one to put???
In general, how do I get a grayscale non-indexed image????
Thanks!!!! Ilaria
Accepted Answer
More Answers (1)
Image Analyst
on 20 Jun 2015
Using
grayImage = rgb2gray(rgbImage);
will give you a gray scale image. I don't know what image_name is, but I suspect you saved a colormap with it when you called imwrite().
I don't think you understand what an indexed image is. An indexed image is just a single valued image, like a uint8 image. If you look at the image with a gray(256) colormap applied, it can look like a normal gray scale version of the image. You can also apply some crazy colormap - color or weird gray scales - and then it might look bizarre. All it means is that the value of the image is to be used as a row index into a colormap so that everywhere you see that value, replace it with the color in the colormap. Now if you call rgb2ind() and tell it to do, like, 8 colors, then the indexed image will have only 8 values, and the colormap will have 8 rows. That image will most likely not look anything like a gray scale version of your color image. But what you call a non-indexed gray scale image could be an indexed image - all you have to do is to display it with a colormap applied and voila! - it's an indexed image even though you didn't change anything in the image itself. So a single-valued image can or cannot be an indexed image - it's just a matter of how you consider it and use or display the gray levels. For example
rgbImage = imread('peppers.png');
grayImage = rgb2gray(rgbImage);
% grayImage can be thought of as a non-indexed image.
% Apply the jet colormap
thisColorMap = jet(256);
colormap(thisColorMap);
% Ta-da! grayImage is now an indexed image because of how it's being used,
% even though I didn't make any actual changes to the grayImage variable.
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!