简体   繁体   中英

Is there a way to create an image from list of lists of tuples containing RGB values?

I am trying to turn a list of rgb values into an image. For the sake of simplicity I will show an example of what I am trying to do instead of my actual code.

I need to turn this list:

[[(255, 255, 0), (128, 128, 128), (211, 211, 211)], [(0, 0, 255), (255, 165, 0), (0, 255, 0)], [(128, 0, 0), (0, 255, 0), (255, 215, 0)]]

Into an image using python.

I am trying to do this using the pillow module but because of the nature of the way the rgb values are stored, i'm struggling to understand how I can go about this.

You can use imgshow from matplotlib

import matplotlib.pyplot as plt

img = [[(255, 255, 0), (128, 128, 128), (211, 211, 211)], [(0, 0, 255), (255, 165, 0), (0, 255, 0)], [(128, 0, 0), (0, 255, 0), (255, 215, 0)]]
plt.imshow(img);

Out:

图像

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