Grayscale image being loaded as an RGB image.

16 ビュー (過去 30 日間)
Aditya
Aditya 2016 年 9 月 10 日
回答済み: Gautham Sholingar 2016 年 9 月 19 日
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 Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by