Grayscale image being loaded as an RGB image.
44 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I converted a jpeg image from RGB to Grayscale, and saved the Grayscale image in my computer as a jpeg image. But when I try to upload the Grayscale image in my workspace, it shows as an RGB image,the image shows a value of 601 X 1050 X 3. Can anyone explain me why this is happening. Thanks
1 comentario
mizuki
el 11 de Sept. de 2016
What function did you use to make it gray? With the following code, I could make it gray. Could you try this on your machine to check if the output image is gray-scale?
A = rand(49,49);
A(:,:,2) = rand(49,49);
A(:,:,3) = rand(49,49);
I = rgb2gray(A);
imshow(I);
pause(1)
close all
imwrite(I, 'im_gray.jpg')
imshow('im_gray.jpg')
Respuestas (1)
Gautham Sholingar
el 19 de Sept. de 2016
Hello Aditya,
I’m assuming you are using MATLAB R2016a. The standard process for converting a color image to grayscale is as follows:
colorImage = imread('colorImage.jpg');
gray = rgb2gray(colorImage);
To save a grayscale image as a JPEG file use the following code:
imwrite(gray,'grayImage.jpg')
When you read in this file using “imread”, the result should be a single channel result i.e aa x bb as opposed to aa x bb x 3
grayRead = imread('grayImage.jpg');
"rgb2gray" is used to convert an RGB image to grayscale
“imwrite” is used to write color and grayscale image data to an image of the required format.
“imshow” can be used to display the color/grayscale image.
0 comentarios
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!