Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 416
Dario Behringer Avatar asked Oct 16 '25 14:10

Dario Behringer


1 Answers

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

like image 94
Dan-Dev Avatar answered Oct 19 '25 05:10

Dan-Dev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!