4

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)
    image.show()

I get an error message:

Cannot handle this data type.

But if I add:

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

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?

3
  • 2
    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. Commented Sep 5, 2012 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 Commented Sep 6, 2012 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. Commented Sep 6, 2012 at 6:35

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.