Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display an numpy array with PIL

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?

like image 564
user1187727 Avatar asked Jan 21 '26 07:01

user1187727


1 Answers

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

like image 136
user1187727 Avatar answered Jan 23 '26 21:01

user1187727



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!