Take the 2-minute tour ×

I want to display a (512, 512) numpy 2d-array of uint16 values with PIL. If I wrote a function:

def display_PIL(nparray):
    image = Image.fromarray(nparray)

I get an error message:

Cannot handle this data type.

But if I add:

def display_PIL(nparray):
    image = Image.fromarray(nparray,'L')

it displays the image, but I have only the upper-right quarter of the image. Is there a solution to have the complete image? Where can I find information regarding the L option and other options?

share|improve this question
This is slightly off topic, but if you want to plot values in an array, why not use matplotlib? It's designed to allow many plot types, and supports numpy arrays directly. –  abought Sep 5 '12 at 22:52
The 'L' type is strictly 8-bit so you should use 'I;16' instead. See pythonware.com/library/pil/handbook/concepts.htm –  Philippe Gauthier Sep 6 '12 at 2:17
Matplotlib is a very powerfull tool for small data set to display. In my cases I have 2d array of more than (100 000, 100 000) values where Matplotlib is not highly powerfull. Ideally I would expect a tool dependent of screen resolution (averaging the array region to display on each pixel displayed on the screen) where a zoom recalculate the displaying area to display. But such a tool apparently doesn't exist. –  user1187727 Sep 6 '12 at 6:35

1 Answer 1

The question is solved using the option 'I;16' in the Image.fromarray function. Many thanks.

share|improve this answer

Your Answer


