1 | initial version |
it's ok I ended up finding. I was not using the correct image mode ! ;-(
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from matplotlib.pyplot import figure
figS=2
figure(num=None, figsize=(figS, 1*figS), dpi=150, facecolor='w', edgecolor='k')
from PIL import Image, ImageColor
imSize=(10,10) # Image size= 10x10 pixels
imageModeL=["RGB","L", "LA", "P", "PA"]
iMmode=imageModeL[0]
im = Image.new(iMmode, imSize)
for i in range(imSize[0]) :
for j in range(imSize[1]) :
im.putpixel((i,j), ImageColor.getcolor("white",iMmode))
im.putpixel((0,0), ImageColor.getcolor('red',iMmode))
im.putpixel((1,0), ImageColor.getcolor('blue', iMmode))
im.putpixel((3,3), ImageColor.getcolor('pink', iMmode))
im.putpixel( (2, 2), ImageColor.getcolor('green', iMmode))
imgPath="/home/ortollj/Downloads/SageMath/IPYNB/"
im.save(imgPath+'tenXtenPixels.png')
img = mpimg.imread(imgPath+"tenXtenPixels.png")
imgplot = plt.imshow(img)