====== Manipulation d'images avec Python ====== ==== Concaténer des images ==== [[https://note.nkmk.me/en/python-pillow-concat-images/|Source]] from PIL import Image im1 = Image.open('data/src/lena.jpg') dst = Image.new('RGB', (im1.width + im1.width, im1.height)) dst.paste(im1, (0, 0)) dst.paste(im1, (im1.width, 0)) dst.save('data/dst/pillow_concat_h.jpg') --------------------------------- ==== Lecture d'image pixel par pixel ==== [[https://deptinfo-ensip.univ-poitiers.fr/ENS/doku/doku.php/stu:python_gui:tuto_images|Source]] from PIL import Image import numpy as np img_pil = Image.open("01bw.png") img = np.array(img_pil) Si l'image est en niveau de gris, le tableau Numpy obtenu n'a que deux dimensions. Le tableau obtenu est row-major: ''img[x][y]''. -------------------------------- ==== Affichage d'une image ==== from PIL import Image import numpy as np import matplotlib.pyplot as plt img_pil = Image.open("01bw.png") img = np.array(img_pil) plt.imshow(img) plt.show() Si l'image est en niveau de gris, il faut le préciser: plt.imshow(img, cmap='gray', vmin=0, vmax=255) Il est possible d'ajouter des lignes horizontales et verticales sur l'affichage de l'image: plt.axhline(y=black_keys_line) plt.axvline(x=x, color='green')