1

I just began working with PyPNG. But in the metadata is one item I don't understand: planes. So two examples of two files:

File 1

'bitdepth': 8, 'interlace': 0, 'planes': 1, 'greyscale': False, 'alpha': False, 'size': (818, 1000)

File 2

'bitdepth': 8, 'interlace': 0, 'planes': 4, 'greyscale': False, 'alpha': True, 'size': (818, 1000)

I skipped the palette information to shorten the snippets and obviously both files only differ in number of planes and the alpha channel.

So far I figured out that in file 2 my pixel array contains exactly four items per pixel defining red, green, blue and alpha. So for each array has a length of 3272 items.

But in file 1 each array has only a length of 818 items.

Therefore can anybody explain if there is a relation between number of planes and array length and how to extract the colors for a given pixel out of file 1?

File 1, File 2

Community
  • 1
  • 1
FlorianM
  • 33
  • 4
  • The planes refers to the number of colour components for monochrome you have 1, for RGBA you have 4, if there was no alpha channel you'd have 3 – EdChum Sep 17 '15 at 12:15
  • Ok, but can the file by monochrome if it contains other colors that black and white? I mean look at file 1 I linked above. In my my understanding it is so colorfull it can never be a monochrome... – FlorianM Sep 17 '15 at 12:19
  • Well that doesn't look right, it could just have incorrect header information, how was this created? – EdChum Sep 17 '15 at 12:21
  • Actually when I analyse both files using xnview, it thinks the first is 8-bit rgb and the other is 32-bit rgb and both have 1 plane, maybe it thinks it's a flat picture so plane refers to geometry? – EdChum Sep 17 '15 at 12:25
  • Acutally bopth files result from an API of wunderground.com and represent weather information. File 1 is a radar precipitation image and file 2 shows the cloud cover as satllite image. But may it be that in file 1 the value of the pixel array reffers to the palette? – FlorianM Sep 17 '15 at 12:28
  • I don't see anything about planes specifically on [wikipedia](https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header) it could be just defaulted information and can be ignored or some metadata that means something to some application, it doesn't look like it's standard ancillary data – EdChum Sep 17 '15 at 12:28
  • Ok, I think I have it. If I use the value from the pixels array for a given pixel as index of the palette I get the right color for that pixel. I rechecked it with GIMP. Thanks for your hint with with the monochrome. It lead me to have a look on the palette. – FlorianM Sep 17 '15 at 12:37
  • rad.png is a palette-mapped (aka [indexed color](https://en.wikipedia.org/wiki/Indexed_color)) image so it defines a palette list mapping numbers (in this case from 0 through to 255) to colors. And then it uses one plane to hold the palette number for each pixel. sat.png uses 4 planes: 1 plane for the red data, 1 for the green, 1 for the blue, and 1 for the opacity/transparency. – PM 2Ring Sep 17 '15 at 12:38

1 Answers1

4

The "planes" are sort of "channels". The number of planes correspond to the dimension of each pixel value.

If you have 1 plane, then each pixel is represented by a single scalar value. This could be a byte, if bitdepth=8; or a bit if bitdepth=1; or a word (16-bits) if bitdepth=16, etc. That value can represent either a Grayscale value (monochrome images) or a palette index (indexed images).

If you have more than one plane, then each pixel is represented by a tuple (array) of scalar values.

The possibilities (in PNG) are:

  planes
   1       [G]             (gray)            monochrome 
   1       [I]            (indexed)          palette   
   2      [G A]         (gray, alpha)        monochrome with transparency
   3     [R G B]     (red, green, blue)      full colour
   4    [R G B A]  (red, green, blue, alpha) full colour with transp.

In your case, the first image has 1 plane and it has a palette. Each pixel ocuppies one byte. In the second case, it's RGBA, each pixel ocuppies 4 bytes.

To extract the pixel values in the first case, you interpret the value (0-255) as an entry into the palette. The palette should include 256 colours (perhaps less), stored as RGB or RGBA

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • Thanks for the answer. Actually I figured that out myself in the meantime but was not exactly sure if my solution would be only dirty scripting or the right solution. Well, know I have certainty. Thanks! – FlorianM Sep 17 '15 at 15:05