Python PIL cut off my 16-bit grayscale image at 8-bit
Question: I'm working on an python program to display images of stars. The images are
16-bit grayscale tiffs. If I try to display them in an extern program, e.g.
ImageMagick they are correct but if I load them in python and then use
'show()' or implement them in a canvas in Tkinter they are, unless a few
pixel, totally white. So I estimate python sets every pixel above 255 to white
but I don't know why. If I load the image and then save it as tiff again,
ImageMagick can show it correct. Thanks for help.


Answer: Try to convert the image to a numpy array and display that:

    
    
    import Image
    import matplotlib.pyplot as plt
    import numpy as np
    
    img = Image.open('image.tiff')
    arr = np.asarray(img.getdata()).reshape(img.size[1], img.size[0])
    plt.imshow(arr)
    plt.show()
    

You can change the color mapping too:

    
    
    from matplotlib import cm
    plt.imshow(arr, cmap=cm.gray)
    

