help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: pngread does not read 12bit gray images


From: de Almeida, Valmor F.
Subject: RE: pngread does not read 12bit gray images
Date: Thu, 17 Jul 2008 21:43:58 -0400

Here is a curve-ball.

If you save the following into a file named img.pgm

P2
# plain gray image; pgm
1 1
65535
4080

And use imagemagick to convert to png, you will get from indentify (on either 
the .png or .pgm files) the following

Image: img.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 1x1+0+0
  Type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 16-bit
  Channel depth:
    Gray: 12-bit
  Channel statistics:
    Gray:
      Min: 255 (0.0622568)
      Max: 255 (0.0622568)
      Mean: 255 (0.0622568)
      Standard deviation: 0 (0)
  Histogram:
         1: ( 4080, 4080, 4080) #0FF00FF00FF0 rgb(6.22568%,6.22568%,6.22568%)


We know for sure that the value in the original file is 4080. Say

pgmhist img.pgm

value   count   b%      w%
-----   -----   --      --
4080    1         100%    100%

Therefore the identify program is messing things up. The real min and max are

0.0622568 * (2^16-1)

However 0.062258 * (2^12-1) is 255 which is NOT what is in the original file. 
Also note that 255 is obtained from bit shifting 4080 to the right by 4.

If you read the image with __magick_read into octave

octave:9> Y = __magick_read__("img.png")
Y = 4080

The final answer to the whole story is that nothing needs to be done. Just read 
the bloody 12-bit gray image with __magick_read__() and it will have the 
correct data.

I ran into some oddities when doing this exercise but I have reached the limits 
of my patience.

--
Valmor

PS. You can create the smallest 12-bit image in a binary file as follows

pgmtopgm  img.pgm
P2
#
1 1
65535
4080




> -----Original Message-----
> From: Søren Hauberg [mailto:address@hidden
> Sent: Thursday, July 17, 2008 3:11 AM
> To: de Almeida, Valmor F.
> Cc: Bill Denney; address@hidden
> Subject: RE: pngread does not read 12bit gray images
> 
> ons, 16 07 2008 kl. 18:49 -0400, skrev de Almeida, Valmor F.:
> > Thank you for pointing this out. I currently read 12-bit png images as
> > follows
> >
> > Y = __magick_read__(filename);
> >
> > Y = bitshift(Y,-4);
> >
> > and this matches the info from running imagemagick identify on the file.
> 
> Would it be possible for you to put your 12-bit image somewhere online?
> I think it would be nice if the future version of 'imread' would support
> 12 bit images in a way where the 'bitshift' wasn't needed. But I don't
> have any 12 bit images at hand so its hard to debug...
> 
> Søren




reply via email to

[Prev in Thread] Current Thread [Next in Thread]