Trying to understand the image matrix
Show older comments
Hi,
I have a jpg image and opened it in MATLAB. It has the following size;
size(pixImage{1}) = 1024 1280 3
I was wondering what the third column represents?
I plotted them up;
figure; image(pixImage{1}(:,:,1))
figure; image(pixImage{1}(:,:,2))
figure; image(pixImage{1}(:,:,3))
but it seems like the image is the same?
Also this is suppose to be a black and white image (or grey) but its blue white and red when I plot according to above. And when I plot;
figure; image(pixImage{1}(:,:))
it seem as if the image has three divisions? there are some visible lines diving the image up in 3 sections?
Accepted Answer
More Answers (1)
Image Analyst
on 16 Sep 2014
0 votes
It is a color image. The third dimension is the color channel: red, green, or blue. If your image is gray (yes, gray is also a color), then all the color channels are identical because that's what gray means - all the color channels have the same values.
I don't know what the visible lines are in your images. Perhaps they're in the image data. Can you post a screenshot?
I don't know why image() shows them in color instead of gray scale. Perhaps some weird colormap is being applied. After you call image(), call colormap(gray(256)) and see if that fixes it.
3 Comments
Lizan
on 16 Sep 2014
You can use imagesc instead and if all your 3 channels are the same just:
imagesc( pixImage{1}(:,:,1));
colormap(gray(256))
should work. Or
image( pixImage{1} );
colormap(gray(256))
should also work too, but don't use pixImage{1}(:,:)
Image Analyst
on 16 Sep 2014
Then it is NOT a gray image. It's a color image with different colors. I made a mistake earlier. Actually if an image is a 3D true color image, colormap() has no effect whatsoever. So you do have a color image, but it is not all shades of gray like you expected. You can attach your image if you want. You can call rgb2gray(rgbImage) to get a grayscale image, or you can take just one of the color channels.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Each one of those is a grayscale/monochrome image and if you use with image() or imshow(), or imagesc(), you can apply a colormap and you will see a difference.
Categories
Find more on Red in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!