how to convert gray image to color image

55 views (last 30 days)
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 Comments
Sivakumaran Chandrasekaran
Thanks Image Analyst. I shall follow it

Sign in to comment.

Accepted Answer

venkat vasu
venkat vasu on 25 Aug 2012
Edited: Walter Roberson on 26 Aug 2012
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...

More Answers (3)

Titus Edelhofer
Titus Edelhofer on 25 Aug 2012
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 Comments

Sign in to comment.


Azzi Abdelmalek
Azzi Abdelmalek on 25 Aug 2012

fereshte
fereshte on 24 May 2014
hi,i tested all codes in this post for my image.but output was gray image.why?
  4 Comments

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!