简体   繁体   中英

How do I plot a numpy rgb array?

How can I plot a numpy array with dimensions (x, y, r, g, b) in one image in Python? Basically, I have to convert these three channels to one?

Install Pillow:

python -m pip install Pillow

Assuming your numpy array's shape is in fact (x, y, (r, g, b)) rather than the unlikely (x, y, r, g, b), and for the sake of the example is named arr , run in python:

import PIL.Image
im = PIL.Image.fromarray(arr)
im.save('out.png')

then plot your output image file with any usual means.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM