I'm trying to convert an array to an image using the Image.fromarray
in PIL but i can't seem to get the shape I'm looking for.
Here's my code:
def affichage(c, disp):
for i in range(len(c)):
for j in range(len(c)):
if c[i][j]==0:
disp[i][j]=[255,255,255]
elif c[i][j]==1:
disp[i][j]=[255,0,0]
elif c[i][j]==2:
disp[i][j]=[0,255,0]
elif c[i][j]==3:
disp[i][j]=[0,0,255]
return disp
disp = affichage(c,disp)
img = Image.fromarray(disp, 'RGB')
img.save('affichage.png', 'png')
img.show()
I'm converting my array with value ranging from 0 to 3 int RGB colors but it display weird rows of color that don't output the same if i plot the array Here is the output image:
Using Image.fromarray
Using matplotlib to plot the array
How can I get the same output as matplotlib ?