[Image-SIG] Reading 16-bit grayscale...

Gajda Michal mgajda at embl-hamburg.de
Thu Jul 24 19:42:51 CEST 2008


Hi,

I'm trying to add CBF support to PIL,
but I cannot read 16-bit grayscale image.
That is surprising as I still have 16-bit TIFF files, that cannot be
read by ImageMagick, but PIL parses them beautifully.

The following code gives an error of 'unrecognized image mode'.
---------------------------------------------------------------
class CBFImageFile(ImageFile.ImageFile):

    format = "CBF"
    format_description = "Crystallographic Binary Format"

    def _open(self):

        # size in pixels (width, height)
        self.size = (2463, 195)
        self.mode = "F;16"
        # data descriptor
        offset = 2421
        self.tile = [
            ("raw",
             (0, 0) + self.size,
             offset,
             (self.mode, 0, 1))
        ]

Image.register_open("CBF", CBFImageFile)

Image.register_extension("CBF", ".cbf")


img = Image.open(textfile)

img.rotate(45).show()
--
  Regards
    Michal



More information about the Image-SIG mailing list