Why does 'imread' reads grayscale images as two-dimensional
显示 更早的评论
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?
采纳的回答
更多回答(2 个)
Walter Roberson
2012-9-11
1 个投票
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 个评论
Jorge Zapata
2012-9-11
Walter Roberson
2012-9-11
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
2012-9-12
编辑:Jorge Zapata
2012-9-12
Walter Roberson
2012-9-12
"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
2012-9-13
Walter Roberson
2012-9-13
John's answer sounds good to me.
Image Analyst
2012-9-11
0 个投票
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 个评论
Jorge Zapata
2012-9-12
编辑:Jorge Zapata
2012-9-12
John
2012-9-12
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
2012-9-12
Can't you also have a tiff stack, where 2 or more grayscale images are all stored in the same tiff file?
John
2012-9-12
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
2012-9-12
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
2012-9-13
Image Analyst
2012-9-13
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!