[Image-SIG] reading 16-bit images in the "raw"

Shemano David A Contr AFRL/SNJM David.Shemano@wpafb.af.mil
Thu, 19 Dec 2002 13:30:07 -0500

i am having difficulty with writing my own file decoder.  the images are 16-bits per pixel straight binary with no header.  i wrote a decoder following the example in the pil documentation, but it seems not to work.  the images are 320x240 16-bits per pixel.  the image file has the right number of bytes. here is my decoder:

import Image, ImageFile

class MerlinImageFile(ImageFile.ImageFile):

    format = "MERLIN"
    format_description = "Merlin camera raw little endian"

    def _open(self):

        self.size = (320, 240)
        self.mode = "F"

        self.tile = [ ("raw", self.size, 0, ("F;16", 0, 1) ) ]

Image.register_open("MERLIN", MerlinImageFile)
Image.register_extension("MERLIN", ".mln")

in the tile attribute the "F;16" is intended to mean that 2 bytes get read in, they are interpreted as a 16-bit little endian integer and the value of that integer is stored as a floating point value in my image.  (please set me straight if i have misinterpreted that)

here is an idle session where i attempt to use the above:

>>> import Image
>>> import MerlinImageFile
>>> im = Image.open("c:\\python22\\dave_projects\\test.mln")
>>> print im.getextrema()
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in ?
    print im.getextrema()
  File "c:\py22\pil\Image.py", line 528, in getextrema
  File "c:\py22\pil\ImageFile.py", line 143, in load
    d.setimage(self.im, e)
TypeError: argument 2 must be sequence of length 4, not 2

any suggestions will be greatly appreciated.  thanks in advance.

dave shemano