Why does 'imread' reads grayscale images as two-dimensional

7 views (last 30 days)
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?

Accepted Answer

John
John on 13 Sep 2012
Copied from comments above with minor edits:
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, either as "associated alpha", "unassociated alpha", or a 3rd catch-all "unspecified".
The ExtraSamples tag is present in this particular file, although it has an incorrect 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).

More Answers (2)

Walter Roberson
Walter Roberson on 11 Sep 2012
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 Comments
Jorge Zapata
Jorge Zapata on 13 Sep 2012
Thanks Walter, in fact is what I did to handle that image. I just wanted to know what that second layer means. Would you mind posting your comment as the answer? or do you think John's answer(in below comment) is more accurated?

Sign in to comment.


Image Analyst
Image Analyst on 11 Sep 2012
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 Comments
Jorge Zapata
Jorge Zapata on 13 Sep 2012
Thanks guys, now I get a better idea of what's going on. Can you please move the comment as the anwer?
Image Analyst
Image Analyst on 13 Sep 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.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!