Avec le module python: PIL il est relativement simple de fusionner plusieurs images. Voici un premier exemple qui à partir d'une image input.png (pour télécharger l'image source allez sur cette page) recopie celle-ci plusieurs fois:
import Image
#opens an image:
im = Image.open("input.png")
im_size = im.size
print im.size
#creates a new empty image, RGB mode, and size 400 by 400.
new_im = Image.new('RGB', (2*im_size[0],2*im_size[1]))
#Here I resize my opened image, so it is no bigger than 100,100
#im.thumbnail((2000,2000))
#Iterate through a 4 by 4 grid with 100 spacing, to place my image
for i in xrange(0,2*im_size[0],im_size[0]):
for j in xrange(0,2*im_size[1],im_size[1]):
#I change brightness of the images, just to emphasise they are unique copies.
#im=Image.eval(im,lambda x: x+(i+j)/30)
#paste the image at location i,j:
new_im.paste(im, (i,j))
new_im.save("output.png", "PNG")
new_im.show()
Autre exemple (pour télécharger les images sources allez sur cette page):
import Image
#opens an image:
im = Image.open("RBG_image_2_adjusted.png")
im1 = Image.open("CTT_adjusted.png")
im2 = Image.open("cloud_phase_c5_adjusted.png")
im3 = Image.open("cloud_phase_c6_adjusted.png")
im_size = im.size
print im.size
#creates a new empty image, RGB mode, and size 400 by 400.
new_im = Image.new('RGB', (2156,2*im_size[1]))
new_im.paste(im, (0,0))
new_im.paste(im2, (0,im_size[1]))
new_im.paste(im1, (1000,0))
new_im.paste(im3, (1000,im_size[1]))
new_im.save("Modis_2008015_1435.png", "PNG")
new_im.show()
Recherches associées
Liens | Site |
---|---|
PIL | PIL module |
how to merge images using python PIL library | stackoverflow |