My image is RGB image but when I used size function it showed me grayscale image.
Ältere Kommentare anzeigen
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"
6 Kommentare
Adam
am 13 Jun. 2018
What is your question? I don't know what the image viewer does, but I assume what you have is a grayscale image that comes with a colourmap.
Using
[I, m] = imread( ... )
to load your image should confirm this.
I assume the Image viewer does that and applies the colourmap to the greyscale (indexed) image.
Akib Rahman
am 13 Jun. 2018
Adam
am 13 Jun. 2018
size('test.jpg')
gives you the size of the char array 'test.jpg' which has nothing to do with the image that may or may not be in such a file, if it exists. You could type
size( 'Some random string' )
and get the same result.
KALYAN ACHARJYA
am 13 Jun. 2018
Agree with Adam ans, its not no of colors, its array size (stack)
Akib Rahman
am 13 Jun. 2018
@Akib Rahman: The link you gave shows how to imread the image into MATLAB and then use size in the image array. In contrast you don't load any data from any file into MATLAB (no imread, no load, nothing at all that actually gets the image file into MATLAB memory), and then instead of testing the size of a variable (which you don't have anyway) you test the size of a 1xN char vector, which might as well be 'Hello World' for all the difference it would make:
>> [~,~,P] = size('Hello World')
P = 1
Why do I get the same value as you did? Is it because I have an image the same size as you... or because I measured the size of an 1xNx1x1x1x... char vector? Your code has nothing to do with any image (unlike the code on the link you gave).
In any case, a simple method to check the image type is to use imfinfo, which does not require reading the image into memory.
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 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).
2 Kommentare
Akib Rahman
am 13 Jun. 2018
Image Analyst
am 13 Jun. 2018
They're RGB images but all color channels are the same. R=G, R=B, and G=B. So it appears as gray scale. If you don't want that, then you need to take a closer look at how the images were saved originally and why they probably got converted to gray scale BEFORE saving to a JPG file.
Kategorien
Mehr zu Images finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


