I'm trying to convert an array filled randomly with numbers (0,1,2) to an image where every number is shown as a different color (preferably picked by me if possible), but I can't find any way to do it. Is there someone who knows if it can be done?
I tried to use PIL but my tries are proving to be very unsatisfactory. I'd really appreciate if someone could help.
I got how to show it as an image, but I don't know how to randomize it. Let's say I have an array with dimensions 400x500 and I'd like to make every cell have one of the three values, can I do something like this? (most of this part of code is from a comment, it's not written by me)
from PIL import Image
import numpy as np
w, h = 500, 400
a = [255, 0, 0]
b = [0, 255, 0]
c = [0, 0, 255]
data = np.array(np.random.random((a,b,c),(h, w, 3), dtype=np.uint8)
#I'd like the random.random to take one of the three values ("[255, 0, 0]", "[0,255, 0]", or "[0, 0, 255]")
img = Image.fromarray(data, 'RGB')
img.save('my.png')
img.show()
Is there a way to do this?
I got it now, thank you for the help everybody!