Search code examples
pythonjpegtiffpython-imaging-library

Convert tiff (I;16) to JPG with PIL/pillow


I have a problem converting a tiff image from a microscope to a jpeg, which should be shown within a web application. I tried the following:

image = Image.open(file_name)
image.convert(mode="RGB")
image.save('my.jpeg')

>>IOError: cannot write mode I;16 as JPEG

Anybody has some experience in converting 16-bit TIFF files to jpegs... I have linked such a file below. Thanks for your help!

https://drive.google.com/open?id=0B04N02JqhWJOWjBPY1RRZkIwbTg


Solution

  • It's a bug. Here is a workaround:

    import Image
    image = Image.open("Fredy1_002.tif")
    image.mode = 'I'
    image.point(lambda i:i*(1./256)).convert('L').save('my.jpeg')
    

    See https://stackoverflow.com/a/7248480/839338