Effacer les filtres
Effacer les filtres

Grayscale image being loaded as an RGB image.

37 vues (au cours des 30 derniers jours)
Aditya
Aditya le 10 Sep 2016
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 commentaire
mizuki
mizuki le 11 Sep 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')

Connectez-vous pour commenter.

Réponses (1)

Gautham Sholingar
Gautham Sholingar le 19 Sep 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.

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