Grayscale image being loaded as an RGB image.
37 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
mizuki
il 11 Set 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')
Risposte (1)
Gautham Sholingar
il 19 Set 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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175069/image.png)
"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 Commenti
Vedere anche
Categorie
Scopri di più su Convert Image Type in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!