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
im1 = Image.open(str(sys.argv[1])).convert('1')
#im1 = Image.open(str(sys.argv[1])).convert('L')
im2 = im1.copy()
#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]
import pickle
loadfile = True
loadfile = False
class Sequence:
def __init__(s):
@ -59,14 +60,14 @@ if loadfile:
else :
seq=Sequence()
for i in range(1):
for i in range(4):
# constitution de la liste des tranches horizontales
# genre comme si qu'on avait un 16 pistes :)
# nombre aleatoire compris dans les limites de l'image
def randHaut():
return random.randint(0, im1.size[1])
return random.randint(0, im1.size[1]/8)*8
if loadfile:
randomCoupeHauteur = seq.randomCoupeHauteur
@ -99,13 +100,19 @@ for i in range(1):
choix_rnd = seq.choix[i]
randomCopyPosi = seq.randomCopyPosi[i]
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
#proportions = seq.proportions[]
choix_rnd = random.randint(0, len(proportions)-1)
#choix_rnd = random.randint(0, len(proportions)-1)
seq.choix.append(choix_rnd)
largeur = proportions[choix_rnd][0]
# positionnement de la copie, aleatoirement, entre 0 et la largeur totale de l'image
randomCopyPosi = random.randint(0, (im1.size[0]-largeur))
@ -130,17 +137,34 @@ for i in range(1):
cx2 = randomCopyPosi + largeur
# decoupage du sample
im3 = im2.crop((cx1,haut,cx2,bas))
print "im3 = im2.crop : "+str(im3.size)
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:
px1 = n
px2 = n + largeur
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
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
loop = loop + 1
''' OPTIONS
'''
def TrancheHorizontale() :
# tirage au hasard de la bande copiee
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):
Hacheur(randomCoupeHauteur[j], randomCoupeHauteur[j+1])
''' SAUVEGARDE
'''
# CTRL + S
#chemin du script : scriptpy = sys.argv[0]
#chemin de l'image : str(sys.argv[1])

View File

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