how to identify grayscale image as an RGB image

5 views (last 30 days)
I am working on grayscale image as input image to cnn network that take RGB image how I can identify grayscale image as an
RGB

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 30 Dec 2022
You can convert a grayscale image into RGB but it wont have a color anyhow, eg:
RGB = cat(3, gray_IMAGE, gray_IMAGE, gray_IMAGE);
imwrite(RGB, OUT_FileName);

More Answers (2)

Walter Roberson
Walter Roberson on 30 Dec 2022
CNN are fed by data stores not by individual images. The recommended practice is to use an augmented image data store. Those permit you to specify the required image size and whether the image should be automatically converted to rgb or to gray. So just by adding the call to the augmented store creation and passing the augmented store instead of the image store, the size and color are automatically fixed up for you.

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 30 Dec 2022
Edited: Sulaymon Eshkabilov on 30 Dec 2022
Grayscale image has one channel and RGB has three channels. How to distinguish them is to use size() fcn.
D = imread(ImageFile1); % RGB
[R1, C1, Channel]=size(D); Channel = 3
D = imread(ImageFile2); % Grayscale
[R2, C2, Channel2]=size(D); Channel2 = 1

Community Treasure Hunt

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

Start Hunting!