Convert tiff (I;16) to JPG with PIL/pillow
11,831
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
Author by
Dario Behringer
Updated on June 05, 2022Comments
-
Dario Behringer almost 2 years
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
-
Dario Behringer almost 7 yearsThanks a lot! Works perfect and saved my day :)
-
DarioB almost 5 yearshey, I am having the same problem! if I plot the image with matplotlib using
ax.imshow(image.point(lambda i:i*(1./256)).convert('L'), cmap=plt.cm.bone)
I can see the image, but the file'my.jpeg'
it is a black image! can you please help? -
DarioB almost 5 yearsI have created this new stackoverflow question with more details stackoverflow.com/questions/56956198/…
-
Salvatore over 3 yearsI'm guessing this answer was copied from Mark Ransom's identical answer here: stackoverflow.com/questions/7247371/python-and-16-bit-tiff
-
Dan-Dev over 3 yearsI have used Pillow for years and PIL before that. I have many code snippets in my code base which I often use to answer questions. I am uncertain of where these originated from as I don't keep track of the source unless it is licenced. I generally link to answers if I find them on the web but if I find a snippet in my code base I just post it, apologies to Mark Ransom if my snippet came from his post originally.