how to convert gray scale image into rgb image?
显示 更早的评论
my project is on iridiology...and it requires to convert the gray scale image to an rgb image to find the basic color of the iris. am in need of the code to convert the gray scale image to rgb image.
2 个评论
TEJASWINI CHINAWALE
2017-9-21
you can use ind2rgb(grayscale image, colormap)...However that cannot convert your grayscale image totally into the coloured one as earlier.
Image Analyst
2017-9-22
You should put this in the "Answer" section. Right below my Answer that says the same thing you just did.
回答(6 个)
Ahmed A. Selman
2013-4-1
Use colormap types, since you are interested with a colored region of interest, I think any colormap format suffices. Example:
close all
clear
clc % just to clear things up
I=imread('333.jpg');
R=rgb2gray(I); % It is gray now
y=colormap(hot(110));
imwrite(R,y,'rgb.jpg','jpg'); % Re-change it to colored one
imshow('rgb.jpg');
5 个评论
Ahmed A. Selman
2013-4-2
Hi ug, The above is an example. You must provide your own grayscale images instead of (R=..), then change it to colored one by the lines (y=..) and (imwrite..). Everything above the line of (y) was used to make a gray image only.
The image ('333.jpg') is on MY Matlab path, of course it might not work with you :)
ug
2013-4-2
Image Analyst
2013-4-2
Please explain why you think it is even possible to recover "the basic color of the iris". Did you snap the original iris image with a color camera or a monochrome camera?
ug
2013-4-2
Image Analyst
2013-4-2
Of course. Wish you'd explained that initially. See my new answer.
Image Analyst
2013-4-1
ug, if your starting image is monochrome, then you cannot determine the original color. You cannot. Not if all you have is the grayscale image. Period.
You can convert a grayscale image into an RGB image using cat():
rgbImage = cat(3, grayImage, grayImage, grayImage);
of course it will look all grayscale even though it is a "true color" RGB image - it's just that all the "colors" are gray. You can apply a pseudocolor lookup table to the gray values, where each gray value gets mapped into some color, to get a multi-colored image, like this:
rgbImage = ind2rgb(grayImage, jet(256));
however the colors are NOT the original colors of the iris as if you had snapped it with a color camera.
2 个评论
ug
2013-4-2
Image Analyst
2013-4-2
Like I said before see my new answer ( http://www.mathworks.com/matlabcentral/answers/69368#answer_80694). ind2rgb() doesn't apply anymore. You will not be using ind2rgb. Again, see my new answer above.
Image Analyst
2013-4-2
You ask: "i hav an image of the iris with all extra features like eye lashes n all..i hav to extract only the iris frm tis image. first i select the two circles of the iris..the resultant image is that the coloured part of the iris is converted to gray scale n the rest is blacked out... but i want to get the original colour....is there ne other method to get the colour of the iris?"
Here's how to do it.
% Make a mask from your circle using poly2mask
% xCircle, yCircle are the coordinates of your circle perimeter.
mask = poly2mask(xCircle, yCircle, rows, columns);
% Now mask the image so that only the original RGB part
% inside the circle remains, and outside the circle is set to black.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask,class(rgbImage)));
ug
2013-4-1
6 个评论
Image Analyst
2013-4-1
编辑:Image Analyst
2013-4-1
Please make this a comment do Ahmed's answer since your response here is not an answer to your question, but a comment to his answer. Strange though that you are willing to accept any old arbitrary colormap (like "hot" which he uses), and think that this will give you the original color of the iris. What's the reasoning for that?
Ahmed A. Selman
2013-4-2
Thanks Analyst for the most valuable suggestion, indeed. But first please read my answer correctly, seems you skipped the (Example) and (any color map might work) parts.
Image Analyst
2013-4-2
I did read it and ran the example before I replied. I figured you must have known that the sample colormap you used, hot, would not be appropriate in his situation. I never did know what you meant by "any colormap format suffices" since the color maps used in ind2rgb must be a prescribed format of a 2D array of N rows by 3 columns with values in the range of 0 to 1. But I took it to indicate that you think there is some colormap out there that would work, and that is where I differ. I don't think there is any colormap out there that would turn his grayscale image into the correctly colored iris image. Where or how would he get such a colormap? You can't take a grayscale image created by, say, rgb2gray() or by taking just one of the color channels, and get back the original color image. You could do an approximate job with an indexed image if you kept the color map returned by rgb2ind(), but the indexed image is not a grayscale image - it looks like garbage if you display it as grayscale. Happy to discuss further....
Ahmed A. Selman
2013-4-2
True, Analyst, I do agree with the idea that when color is lost it cannot be retained correctly. Thus any color map can do the job mentioned in the question with the same quality, give or take; they all will NOT be correct, but ANY could specifically isolate iris from the rest, at least better than a grayscale image. In fact I do wonder what does (determine the basic color of the iris from gray images) means, I keep reading amazing stuff here. Correctly colored iris image from gray image is, without doubt, not possible unless a true image was used to specify the colormap .. and if true images do exist then why convert them to gray and ask how to retain the color?..
Anyway, industrially colored images do look like garbage, even when using highly sophisticated image software (truth has only one face..) but does it matter if it was using hot or jet or any other map? If there is a difference please specify what kind is better -- new info are useful and appreciated, always. If not, however, then old or new colormaps will be all as crappy as the same, right? :)
Image Analyst
2013-4-2
We're in agreement here. If all you want to do is to colorize it, you can pick whatever colormap you feel looks best or suits your needs - it's totally subjective.
Ahmed A. Selman
2013-4-2
My exact point. Thank you.
G.Liz
2013-7-31
0 个投票
Does anyone know how to segment the sclera of the eye ?
1 个评论
Walter Roberson
2013-7-31
Please start a new Question for that.
类别
在 帮助中心 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!