The MATLAB help for imread says:
A = imread(filename, fmt)
The return value A is an array containing the image data. If the file contains a grayscale image, A is an M-by-N array. If the file contains a truecolor image, A is an M-by-N-by-3 array.
I thought it would generate 3 matrices for the RGB (one with the Red, one with the Green and one with the Blue), so I did:
img = imread('myimg')
size(img) % ans = 720 960 3
imshow(img) % the original image
imshow(img(:,:,1)) % print grayscaled image
imshow(img(:,:,2)) % print grayscaled image
imshow(img(:,:,3)) % print grayscaled image
And, as commented, the 3 images are just the original but grayscaled. So, why are 3 images generated?
(using Matlab R2011b)
Uh, no. There are not 3 images, there is a single image represented as a 3D matrix, or, a stack of 3 matrices, one for each channel (R,G,B). When you do
img(:,:,1)you are extracting the matrix corresponding to the red channel, and when you callimshow(img(:,:,1))you tell Matlab to interpret that matrix as an image (and because that matrix has only one channel, it interprets it as a gray scale image). The three calls to imgshow should then show each channel as a grayscale image. They should not be equal, though; to be sure of that, use some image that has eg a pure red corner: that would display as white in the first channel, black in the others.This question is more apt for stackoverflow, though.