Problem on gray scale image.

Hi. i used gray = rgb2gray(I) at command window but why can't i get a grayscale image? thank you!

Respuestas (2)

Walter Roberson
Walter Roberson el 19 de Sept. de 2012

0 votos

grayscaleimage = rgb2gray(I);
image(grayscaleimage);
colormap(gray);
Please note that "gray" is a MATLAB function for constructing grayscale colormaps. Writing to a variable named "gray" interferes with using the function "gray".
Esther
Esther el 20 de Sept. de 2012

0 votos

thanks for answer. i did this tutorial, http://www.mathworks.com/videos/developing-algorithms-with-matlab-68914.html just that i used a color image instead of a gray image. but i couldn't get a grayscale.

6 comentarios

Walter Roberson
Walter Roberson el 20 de Sept. de 2012
The one line of code you show above would only convert the image and write it into the variable "gray" and would not display the image at all, and would not use a correct colormap in the display.
Please show us some code in which you can reproduce the problem.
Image Analyst
Image Analyst el 20 de Sept. de 2012
Are you saying that you read the image using imread() into an array, and then you passed that image into rgb2gray() as Walter advised, and that you got an rgb image back out? I find that very surprising as I've never ever experienced that failure.
rgbImage = imread(filename);
grayImage = rgb2gray(rgbImage);
[rows columns numberOfColorChannels] = size(rgbImage)
[rows2 columns2 numberOfColorChannels2] = size(grayImage)
Run that code on your image and tell me what shows up in the command window. Please upload your original rgb image (which would be a BMP, TIFF, JPG, or PNG file, not a .fig file, and not a screenshot), and your code so I can verify before I submit a bug report.
Esther
Esther el 20 de Sept. de 2012
rows =
1936
columns =
2592
numberOfColorChannels =
3
rows2 =
1936
columns2 =
2592
numberOfColorChannels2 =
1
Walter Roberson
Walter Roberson el 20 de Sept. de 2012
Okay, and then what do you do with grayImage to display it?
Image Analyst
Image Analyst el 20 de Sept. de 2012
Editada: Image Analyst el 20 de Sept. de 2012
So you DID get a gray scale image. Why did you say you did not?

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 19 de Sept. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by