Trying to understand the image matrix

25 visualizaciones (últimos 30 días)
Lizan
Lizan el 16 de Sept. de 2014
Editada: Lizan el 16 de Sept. de 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?

Respuesta aceptada

John D'Errico
John D'Errico el 16 de Sept. de 2014
Editada: John D'Errico el 16 de Sept. de 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 comentarios
Image Analyst
Image Analyst el 16 de Sept. de 2014
Try extracting the image from the cell first, then getting the profile
thisImage = pixProfile{i};
thisColumn1Profile = thisImage(:, 1);
Lizan
Lizan el 16 de Sept. de 2014
Editada: Lizan el 16 de Sept. de 2014
Yes, I made an array of pixProfile and this seemed to solve the problem. =)
Thank you!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 16 de Sept. de 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 comentarios
Adam
Adam el 16 de Sept. de 2014
Editada: Adam el 16 de Sept. de 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
Image Analyst el 16 de Sept. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Blue en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by