Grayscale image being loaded as an RGB image.

37 次查看(过去 30 天)
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 个评论
mizuki
mizuki 2016-9-11
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')

请先登录,再进行评论。

回答(1 个)

Gautham Sholingar
Gautham Sholingar 2016-9-19
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.

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by