My image is RGB image but when I used size function it showed me grayscale image.
50 views (last 30 days)
I have an image. When I open it using windows photo viewer it showed RGB image but when I use size function of Matlab for finding color channel it showed me "1". That's mean it is the grayscale image. The image also attached.
My Matlab code is:
[rows, columns, numberOfColorChannels] = size('test.jpg');
Output is: numberOfColorChannels is "1"
Stephen23 on 13 Jun 2018
Edited: Stephen23 on 13 Jun 2018
There is no problem, you just did not actually read the image into MATLAB. It works perfectly for me:
>> [img,map] = imread('test.jpg');
96 200 3
>> S = imfinfo('test.jpg');
ans = truecolor
Nope, not a grayscale image at all.
More Answers (1)
Image Analyst on 13 Jun 2018
You're calling size() on the filename string, not the RGB image. You need to call imread() to read the image into a variable:
rgbImage = imread('test.jpg');
[rows, columns, numberOfColorChannels] = size(rgbImage)
like I did in my demo where you pulled this code from (but altered it).