Reputation: 31
Is there a simple way to convert a 32-bit .tif to 16-bit .tif? In IDL, write_tiff allows /short instead of /float. Does Python do that? Instead, I have tried this:
i32 = Image.open('image.tif')
<Image.Image image mode=F size=2016x2016 at 0x102A3E998>
i32.convert('L').save('newimage.tif')
ImageJ (viewer) opens the tif and says that this image is 8-bit, not 16-bit.
Upvotes: 3
Views: 7090
Reputation: 133879
From PIL documentation: The 'L'
mode is for 8-bit greyscale images, and your original image is a 32-bit float (mode 'F'
), not integer! To get 16 bit integer images, you can try to use 'I;16'
for the mode; this is at least supported in my Pillow 2.0.0 (Ubuntu 14.04):
f32 = Image.open('image.tif')
f32.convert('I;16').save('newimage.tif')
Upvotes: 3
Reputation: 43495
The Python Imaging Library doesn't support 16-bit pixel depth. See "modes" in the concepts section of the Handbook.
The same goes for the derivative library Pillow.
Try e.g. ImageMagick (which has python bindings) with the -depth
option.
Upvotes: 1