add pixelisation effect

This commit is contained in:
rep 2015-11-11 13:29:49 +01:00
parent a60bd13677
commit 3ec643b1a0
4 changed files with 3247 additions and 390 deletions

View File

@ -21,6 +21,7 @@ import ImageEnhance
#ouvertrure de l'image source et conversion en mode couleur 1bit #ouvertrure de l'image source et conversion en mode couleur 1bit
im1 = Image.open(str(sys.argv[1])).convert('1') im1 = Image.open(str(sys.argv[1])).convert('1')
#im1 = Image.open(str(sys.argv[1])).convert('L')
im2 = im1.copy() im2 = im1.copy()
#rapport d'allongement de la nouvelle image par rapport à la largeur de l'image originale #rapport d'allongement de la nouvelle image par rapport à la largeur de l'image originale
@ -33,7 +34,7 @@ Larg = im1.size[0]
Haut = im1.size[1] Haut = im1.size[1]
import pickle import pickle
loadfile = True loadfile = False
class Sequence: class Sequence:
def __init__(s): def __init__(s):
@ -59,14 +60,14 @@ if loadfile:
else : else :
seq=Sequence() seq=Sequence()
for i in range(1): for i in range(4):
# constitution de la liste des tranches horizontales # constitution de la liste des tranches horizontales
# genre comme si qu'on avait un 16 pistes :) # genre comme si qu'on avait un 16 pistes :)
# nombre aleatoire compris dans les limites de l'image # nombre aleatoire compris dans les limites de l'image
def randHaut(): def randHaut():
return random.randint(0, im1.size[1]) return random.randint(0, im1.size[1]/8)*8
if loadfile: if loadfile:
randomCoupeHauteur = seq.randomCoupeHauteur randomCoupeHauteur = seq.randomCoupeHauteur
@ -99,13 +100,19 @@ for i in range(1):
choix_rnd = seq.choix[i] choix_rnd = seq.choix[i]
randomCopyPosi = seq.randomCopyPosi[i] randomCopyPosi = seq.randomCopyPosi[i]
else: else:
proportions = [(160,6),(120,4),(120,8),(80,16),(60,16),(20,32),(8,24),(8,16),(5,64),(3,24),(2,24),(1,256),(1,128),(1,64),(1,32),(1,16),(1,8)] '''
8 16 24 32 40 48 56 64 72 80 88 96 104 112 120 128 136 144 152 160 168
'''
#proportions = [(160,6),(120,4),(120,8),(80,16),(60,16),(20,32),(8,24),(8,16),(5,64),(3,24),(2,24),(1,256),(1,128),(1,64),(1,32),(1,16),(1,8)]
proportions = [(160,6),(120,4),(120,8),(80,16),(64,16),(24,32),(8,24),(8,16)]
seq.proportions = proportions seq.proportions = proportions
#proportions = seq.proportions[] #proportions = seq.proportions[]
choix_rnd = random.randint(0, len(proportions)-1) choix_rnd = random.randint(0, len(proportions)-1)
#choix_rnd = random.randint(0, len(proportions)-1) #choix_rnd = random.randint(0, len(proportions)-1)
seq.choix.append(choix_rnd) seq.choix.append(choix_rnd)
largeur = proportions[choix_rnd][0]
# positionnement de la copie, aleatoirement, entre 0 et la largeur totale de l'image # positionnement de la copie, aleatoirement, entre 0 et la largeur totale de l'image
randomCopyPosi = random.randint(0, (im1.size[0]-largeur)) randomCopyPosi = random.randint(0, (im1.size[0]-largeur))
@ -130,17 +137,34 @@ for i in range(1):
cx2 = randomCopyPosi + largeur cx2 = randomCopyPosi + largeur
# decoupage du sample # decoupage du sample
im3 = im2.crop((cx1,haut,cx2,bas)) im3 = im2.crop((cx1,haut,cx2,bas))
print "im3 = im2.crop : "+str(im3.size)
draw = ImageDraw.Draw(im4) draw = ImageDraw.Draw(im4)
loop = 0
#collage, n fois, du sample loop = 0
pixelSizeIndex = random.randint(0,20)
pixelSizeList = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,4,8]
pixelSize = pixelSizeList[pixelSizeIndex]
print " pixelSize = "+str(pixelSize)
''' COLLAGE DU SAMPLE
'''
while loop<repeat: while loop<repeat:
px1 = n px1 = n
px2 = n + largeur px2 = n + largeur
draw = ImageDraw.Draw(im3) draw = ImageDraw.Draw(im3)
''' PIXELISATION
'''
im3 = im3.resize((im3.size[0]/pixelSize, im3.size[1]/pixelSize), Image.NEAREST)
im3 = im3.resize((im3.size[0]*pixelSize, im3.size[1]*pixelSize), Image.NEAREST)
print "im3.size="+str(im3.size)
print "im4.size="+str(im4.size)
#lignes colorées de 1 pix #lignes colorées de 1 pix
draw.line((im3.size[0]-1, 0, im3.size[0]-1, im3.size[1]-1), fill="rgb(255,255,255)") draw.line((im3.size[0]-1, 0, im3.size[0]-1, im3.size[1]-1), fill="rgb(255,255,255)")
@ -149,6 +173,8 @@ for i in range(1):
n = n + largeur n = n + largeur
loop = loop + 1 loop = loop + 1
''' OPTIONS
'''
def TrancheHorizontale() : def TrancheHorizontale() :
# tirage au hasard de la bande copiee # tirage au hasard de la bande copiee
pos = random.randint(0, im1.size[1]-im1.size[1]/20) pos = random.randint(0, im1.size[1]-im1.size[1]/20)
@ -167,6 +193,8 @@ for i in range(1):
for j in range(len(randomCoupeHauteur)-1): for j in range(len(randomCoupeHauteur)-1):
Hacheur(randomCoupeHauteur[j], randomCoupeHauteur[j+1]) Hacheur(randomCoupeHauteur[j], randomCoupeHauteur[j+1])
''' SAUVEGARDE
'''
# CTRL + S # CTRL + S
#chemin du script : scriptpy = sys.argv[0] #chemin du script : scriptpy = sys.argv[0]
#chemin de l'image : str(sys.argv[1]) #chemin de l'image : str(sys.argv[1])

View File

@ -4,7 +4,6 @@ from time import gmtime, strftime
fichier=sys.argv[1] fichier=sys.argv[1]
try: try:
im1 = Image.open(fichier).convert('1') im1 = Image.open(fichier).convert('1')
im2 = im1.copy() im2 = im1.copy()
@ -28,7 +27,6 @@ while x < im1.size[0] :
# ALPHA tout bete : # ALPHA tout bete :
im3 = Image.blend(im1, im2, 0.8) im3 = Image.blend(im1, im2, 0.8)
n = "%05d" % x n = "%05d" % x
nomdefichier = "horizontal"+n+".png" nomdefichier = "horizontal"+n+".png"
im3.save(nomdefichier, "PNG") im3.save(nomdefichier, "PNG")
@ -43,9 +41,3 @@ print " OUTPUT FINAL : "+fichier+".final.mp4"
# Nettoyage # Nettoyage
os.system("rm horizontal*.png") os.system("rm horizontal*.png")

40
pixelate.py Normal file
View File

@ -0,0 +1,40 @@
from PIL import Image
'''
backgroundColor = (0,)*3
'''
pixelSize = 8
image = Image.open('pixelate_input.png')
image = image.resize((image.size[0]/pixelSize, image.size[1]/pixelSize), Image.NEAREST)
image = image.resize((image.size[0]*pixelSize, image.size[1]*pixelSize), Image.NEAREST)
pixel = image.load()
'''
for i in range(0,image.size[0],pixelSize):
for j in range(0,image.size[1],pixelSize):
for r in range(pixelSize):
pixel[i+r,j] = backgroundColor
pixel[i,j+r] = backgroundColor
'''
image.save('pixelate_output.png')
'''
load
im.load()
Allocates storage for the image and loads it from the file (or from the source, for lazy operations). In normal cases, you dont need to call this method, since the Image class automatically loads an opened image when it is accessed for the first time.
(New in 1.1.6) In 1.1.6 and later, load returns a pixel access object that can be used to read and modify pixels. The access object behaves like a 2-dimensional array, so you can do:
pix = im.load()
print pix[x, y]
pix[x, y] = value
Access via this object is a lot faster than getpixel and putpixel.
'''

File diff suppressed because it is too large Load Diff