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!