how to convert gray image to color image

23 vues (au cours des 30 derniers jours)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran le 25 Août 2012
Commenté : fereshte le 24 Mai 2014
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 commentaires
Image Analyst
Image Analyst le 25 Août 2012
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 le 26 Août 2012
Thanks Image Analyst. I shall follow it

Connectez-vous pour commenter.

Réponse acceptée

venkat vasu
venkat vasu le 25 Août 2012
Modifié(e) : Walter Roberson le 26 Août 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...

Plus de réponses (3)

Titus Edelhofer
Titus Edelhofer le 25 Août 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 commentaires
Image Analyst
Image Analyst le 25 Août 2012
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 le 26 Août 2012
Thanks Image Analyst

Connectez-vous pour commenter.


Azzi Abdelmalek
Azzi Abdelmalek le 25 Août 2012

fereshte
fereshte le 24 Mai 2014
hi,i tested all codes in this post for my image.but output was gray image.why?
  4 commentaires
Image Analyst
Image Analyst le 24 Mai 2014
Please post your image and your code as a new question.
fereshte
fereshte le 24 Mai 2014
ok

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by