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 Kommentare

Image Analyst
Image Analyst am 25 Aug. 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!
Thanks Image Analyst. I shall follow it

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

venkat vasu
venkat vasu am 25 Aug. 2012
Bearbeitet: Walter Roberson am 26 Aug. 2012

0 Stimmen

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...

Weitere Antworten (3)

Titus Edelhofer
Titus Edelhofer am 25 Aug. 2012

0 Stimmen

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 Kommentare

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);
Thanks Image Analyst

Melden Sie sich an, um zu kommentieren.

fereshte
fereshte am 24 Mai 2014

0 Stimmen

hi,i tested all codes in this post for my image.but output was gray image.why?

4 Kommentare

Image Analyst
Image Analyst am 24 Mai 2014
It's possible for a color image to have only gray colors in it. Gray is a color too. If all your red, green, and blue channels were the same image, then creating a color image out of them will make a gray image.
If you want to apply a pseudocolor look up table to an image to create a pseudocolored image, you can use colormap() and ind2rgb().
fereshte
fereshte am 24 Mai 2014
Bearbeitet: fereshte am 24 Mai 2014
thanks.for jpg images, this code return me color image but for bmp color image give me graye image. original images are color(red.green.blue).i apply them in my code but output images were gray!! i use above codes to convert them to color image but output was gray image again.how correct it?
Image Analyst
Image Analyst am 24 Mai 2014
Please post your image and your code as a new question.
fereshte
fereshte am 24 Mai 2014
ok

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by