Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16-bit TIFF files truncated to 0..255 before conversion to float #274

tdsmith opened this issue Jul 8, 2013 · 2 comments


None yet
3 participants
Copy link

commented Jul 8, 2013

Example data file: (a 16-bit TIFF container with pixel values spanning a 12-bit range, which is common in scientific imaging)

Opening the file with gives the expected result:

>>> im, im.mode
(<PIL.TiffImagePlugin.TiffImageFile image mode=I;16 size=1344x1024 at 0x1074A2518>, 'I;16')
>>> im.getpixel((5,5))

But converting to a float type clips all pixel values above 255 to 255:

>>> im.convert('F').getpixel((5,5))

Conversion to float should not clip 16-bit integer values.


This comment has been minimized.

Copy link

commented Jul 9, 2013

It appears (from Convert.c) that there's no direct conversion from I;16 to F. There are I to F, and I;16 to I, but nothing that works in one step. [edit, though, I'm not actually seeing how it should work at all, since it should return a conversion not supported error. edit 2, this is the truncation. ]

def _test_float_conversion(im):
    orig = im.getpixel((5,5))
    converted = im.convert('F').getpixel((5,5))
    assert_equal(orig, converted)

def test_12bit():
    im ='Tests/images/12bit.tif')

def test_12bit_workaround():
    im ='Tests/images/12bit.tif')

It looks like a conversion for the I;16 modes -> F should be straight forward.


This comment has been minimized.

Copy link

commented Jul 15, 2013

In case anyone is as retarded as me, and completely didn't twig from the above answer, just use


This is what Wiredfool suggested, so credit to him.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.