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

本小妞迷上赌 提交于 2019-12-11 04:27:08

问题


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


回答1:


It's either a bug or unimplemented in PIL/Pillow. 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')


来源:https://stackoverflow.com/questions/43978819/convert-tiff-i16-to-jpg-with-pil-pillow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!