Why does 'imread' reads grayscale images as two-dimensional
Mostrar comentarios más antiguos
According to matlab documentation imread does the following: "If the file contains a grayscale intensity image, A is a two-dimensional array", but I simply don't get what the second dimension means.
As far as I can see the second dimension just stores 255 value, but what is this supposed to mean?
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 11 de Sept. de 2012
1 voto
The first dimension is rows. The second dimension is columns.
In a "true-color" image, the third dimension would be the color planes, such as Red, Green, Blue, or HSV, or CMYK.
6 comentarios
Jorge Zapata
el 11 de Sept. de 2012
Walter Roberson
el 11 de Sept. de 2012
Which document are you examining?
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. For TIFF files containing color images that use the CMYK color space, A is an M-by-N-by-4 array
Which version are you using? What kind of file are you reading?
I have never seen the result you are mentioning.
Jorge Zapata
el 12 de Sept. de 2012
Editada: Jorge Zapata
el 12 de Sept. de 2012
Walter Roberson
el 12 de Sept. de 2012
"two-dimensional" in that document means M x N, not two bit planes.
imfinfo() indicates that particular image, lake.tif, has a bitdepth of 16. 16 bit grayscale TIFF images are not supported by imread().
The TIFF class reports that there are problems with the TIFF header, and interprets the file as 8 bit.
The details reported by imfinfo() hint that the file might be a 16 bit TIFF image that was stored something like the first 8 bits are in one bit plane and the second 8 bits are in a second bit plane. The all-255 result for the second bit plane hints that there is not actually any useful information in that second bit plane, and that you should simply extract the first bitplane, A(:,:,1)
Jorge Zapata
el 13 de Sept. de 2012
Walter Roberson
el 13 de Sept. de 2012
John's answer sounds good to me.
Image Analyst
el 11 de Sept. de 2012
0 votos
A two dimensional image has two independent coordinates that define the location, and a value that the image has at that location. For example, you might want to look at row 100, column 200. That is two dimensions. Now the image there will have a value, say it's 255 or 123 or 42 or whatever, but the fact that is has a value does not change the fact that it's still two dimensions. There are two independent variables (row and column) - doesn't that mean 2D in your book? Having a value doesn't make it a 3D image because there are not 3 independent values you can specify. Once you've specified two, the value is determined.
Look at a simpler example, a curve y = x^2. Just because this traces out a curve on a flat 2D piece of paper, does not make it a 2 dimensional curve. It's still 1D. You can only specify the x value and then the y value is completely determined.
7 comentarios
Jorge Zapata
el 12 de Sept. de 2012
Editada: Jorge Zapata
el 12 de Sept. de 2012
John
el 12 de Sept. de 2012
Hi Jorge, it's actually allowed for TIFFs to have more planes than one would normally think. For example, an RGB TIFF could have a 4th layer for opacity or alpha, just so long as the first 3 layers are R, G, and B. It would also be required in that case (according to the TIFF spec) for the TIFF to define another tag called 'ExtraSamples' that accurately describes that 4th layer.
The ExtraSamples tag is present in your file, although it has an illegal value. Basically the only interpretation would be for the first layer to be considered the "real" grayscale part of the image, and that 2nd layer as unassociated alpha (read the TIFF spec, section 18, for an explanation of unassociated alpha).
Hope this makes sense.
Image Analyst
el 12 de Sept. de 2012
Can't you also have a tiff stack, where 2 or more grayscale images are all stored in the same tiff file?
John
el 12 de Sept. de 2012
Yes, that is definitely more common, but the ExtraSamples tag IS part of the TIFF specification and allows one to tack on as many extra channels or planes as one wants, so long as the intent of the extra channels is made clear by the ExtraSamples tag. And it's really the only way to properly handle opacity.
Walter Roberson
el 12 de Sept. de 2012
A TIFF stack is handled by storing "subimages" if I understand correctly. That would show up quite differently. imread() by default reads only the first image.
Jorge Zapata
el 13 de Sept. de 2012
Image Analyst
el 13 de Sept. de 2012
Only John can do that if his name is to be attached to the answer. I'd have to copy it to a new answer but then it would have my name attached to it.
Categorías
Más información sobre Convert Image Type en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!