how to convert gray image to color image

조회 수: 24 (최근 30일)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012년 8월 25일
댓글: fereshte 2014년 5월 24일
Image=imread('fog1.bmp');
[m n r]=size(Image)
rgb=zeros(m,n,3);
rgb(:,:,1)=Image;
rgb(:,:,2)=rgb(:,:,1);
rgb(:,:,3)=rgb(:,:,1);
Image=rgb/255;
figure,imshow(Image);
I am getting error in the line rgb(:,:,1)=Image;
Can anyone tell whats the error
  댓글 수: 2
Image Analyst
Image Analyst 2012년 8월 25일
Siva, you've been asking enough questions here that you should learn how to format lines as code. Here's a tip: Just simply highlight the lines of code and click the {}Code icon above the text box. That will format it so that we will see it properly. I've done it for you this time but try to do it yourself next time - it's not hard. Thanks!
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012년 8월 26일
Thanks Image Analyst. I shall follow it

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

채택된 답변

venkat vasu
venkat vasu 2012년 8월 25일
편집: Walter Roberson 2012년 8월 26일
Image=imread('fog1.bmp');
if size(Image,3)==3
Image=rgb2gray(Image);
end
[m n r]=size(Image);
rgb=zeros(m,n,3);
rgb(:,:,1)=Image;
rgb(:,:,2)=rgb(:,:,1);
rgb(:,:,3)=rgb(:,:,1);
Image=rgb/255;
figure,imshow(Image);
Try this code...

추가 답변 (3개)

Titus Edelhofer
Titus Edelhofer 2012년 8월 25일
Hi,
what's the value of r? One? Or three? I guess your Image is already an RGB image, only that R, G and B are always equal (and therefore you have gray) ...
Titus
  댓글 수: 2
Image Analyst
Image Analyst 2012년 8월 25일
So the proper code would most likely be:
rgbImage = imread('fog1.bmp');
[rows columns numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels == 1
% It's monochrome, so convert to color.
rgbImage = cat(3, rgbImage, rgbImage, rgbImage);
end
imshow(rgbImage);
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012년 8월 26일
Thanks Image Analyst

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


Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 25일

fereshte
fereshte 2014년 5월 24일
hi,i tested all codes in this post for my image.but output was gray image.why?
  댓글 수: 4
Image Analyst
Image Analyst 2014년 5월 24일
Please post your image and your code as a new question.
fereshte
fereshte 2014년 5월 24일
ok

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

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by