how to convert gray scale image into rgb image?

조회 수: 17 (최근 30일)
ug
ug 2013년 4월 1일
댓글: Image Analyst 2017년 9월 22일
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
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
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
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
ug
ug 2013년 4월 2일
here is the procedure, 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?
Image Analyst
Image Analyst 2013년 4월 2일
Of course. Wish you'd explained that initially. See my new answer.

댓글을 달려면 로그인하십시오.


Image Analyst
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
ug 2013년 4월 2일
am getting an error in the ind2rgb function... sayin the dimensions don match
Image Analyst
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
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)));

Mahdi
Mahdi 2013년 4월 1일
Gabriel made a script for that. You can find it here.

ug
ug 2013년 4월 1일
@Ahmed A. Selman
Am getting the following errors:
??? Error: File: C:\MATLAB7\toolbox\images\images\private\checkinput.m Line: 38 Column: 1
Incomplete or misformed expression or statement.
Error in ==> images\private\checkstrs at 26 checkinput(in, 'char', 'row', function_name, variable_name, argument_position);
Error in ==> imlincomb>ParseInputs at 95 output_class = checkstrs(varargin{end}, valid_strings, mfilename, ...
Error in ==> imlincomb at 83 [images, scalars, output_class] = ParseInputs(varargin{:});
Error in ==> rgb2gray at 58 I = imlincomb(coef(1),X(:,1),coef(2),X(:,2),coef(3),X(:,3), ...
Error in ==> trial at 5 R=rgb2gray(I); % It is gray now
  댓글 수: 6
Image Analyst
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
Ahmed A. Selman 2013년 4월 2일
My exact point. Thank you.

댓글을 달려면 로그인하십시오.


G.Liz
G.Liz 2013년 7월 31일
Does anyone know how to segment the sclera of the eye ?

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by