Trying to understand the image matrix
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lizan
am 16 Sep. 2014
Bearbeitet: Lizan
am 16 Sep. 2014
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?
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 16 Sep. 2014
Bearbeitet: John D'Errico
am 16 Sep. 2014
To add a few comments to what Stephen and Image have already told you...
1. That third column of the 3-dimensional image array tells us that the image has 3 planes, here (red, green, blue) since the image is RGB. This is a color image. Gray is a valid color, just not a terribly exciting one. (And it is available in more than 50 shades.)
2. The statement that all three channels are the same when plotted separately tells us that it is indeed a grayscale image. Such an image appears neutral, in shades of gray because all three channels (in terms of RGB) are the same.
3. When you do this:
figure; image(pixImage{1}(:,:))
Matlab converts the image array into a TWO dimensional array, reshaping it. It was three dimensional, but the (:,:) forced it to reshape. For example:
A = rand(2,3,4);
size(A(:,:))
ans =
2 12
MATLAB just does what you tell it to do. If you tell it to do something silly, it is quite happy to comply.
So in your case,
size(pixImage{1}(;,:))
would be [1024 3840].
5 Kommentare
Image Analyst
am 16 Sep. 2014
Try extracting the image from the cell first, then getting the profile
thisImage = pixProfile{i};
thisColumn1Profile = thisImage(:, 1);
See this for a good intuitive explanation of cell arrays: http://matlab.wikia.com/wiki/FAQ#Can_you_program_up_the_algorithm_in_this_article_for_me_and_explain_it_to_me.3F
Weitere Antworten (1)
Image Analyst
am 16 Sep. 2014
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 Kommentare
Image Analyst
am 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.
Siehe auch
Kategorien
Mehr zu Blue finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!