pixelisation v2

This commit is contained in:
rep 2015-12-10 01:46:48 +01:00
parent 0de90a4934
commit 8045d3c2ba
5 changed files with 6348 additions and 10663 deletions

1112
ghost-diagrams-0.8.py Normal file

File diff suppressed because it is too large Load Diff

268
haacheuur.daube.py Normal file
View File

@ -0,0 +1,268 @@
#!/usr/bin/python
# coding: utf-8
# haacheuur 0.24
# port industriel de port la nouvelle - couleur - 60cm*30cm
# image source : pln.jpg
# image obtenue : pln..20150910-11h59m53s.jpg
# pln.png 3936x1024 pix
'''
image input puredata : 16384 width x 768 height
donc par exemple, pour 3 images :
3 x 16384 = 49152 pixels en tout
'''
import sys
import Image
import random
import os
import ImageDraw
import ImageFont
import ImageFilter
from time import gmtime, strftime
import time
if not len(sys.argv) > 1:
raise SystemExit("Usage: %s image_source" % sys.argv[0])
# modifs du 30/10/2013
import ImageEnhance
#rapport d'allongement de la nouvelle image par rapport à la largeur de l'image originale
allongement = 1
#ouverture de l'image source et conversion en mode couleur 1bit
#1 bit (sys.argv[1])).convert('1') et niveaux de gris : (sys.argv[1])).convert('L')
im1 = Image.open(str(sys.argv[1]))
im2 = im1.copy()
im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
im5 = Image.new("RGBA",(im1.size[0], im1.size[1]))
im4 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1]))
#im4 = Image.new("RGBA",(49152, im1.size[1]))
Larg = im1.size[0]
Haut = im1.size[1]
import pickle
loadfile = False
class Sequence:
def __init__(s):
randomCoupeHauteur = []
s.randomCopyPosi =[]
s.proportions=[]
s.choix=[]
s.sizeOutput=None
s.sizeInput=None
"""
seq = dict()
seq["randomCoupeHauteur"] = []
seq["randomCopyPosi"] = []
seq["proportions"] = []
seq["choix"] = []
seq["sizeOutput"]= im4.size
seq["sizeInput"] = im1.size
"""
if loadfile:
seq=pickle.load(open("test.pickle"))
else :
seq=Sequence()
for i in range(1):
# 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]/8)*8
if loadfile:
randomCoupeHauteur = seq.randomCoupeHauteur
else:
randomCoupeHauteur = [0, \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
im1.size[1]]
# rangement des valeurs des plus petites au plus grandes
randomCoupeHauteur.sort()
seq.randomCoupeHauteur = randomCoupeHauteur
# les hachures
def Hacheur(haut, bas) :
n=0
i=0
#!!!!!!!!!!
while n<im4.size[0] :
if loadfile:
proportions = seq.proportions
choix_rnd = seq.choix[i]
randomCopyPosi = seq.randomCopyPosi[i]
else:
'''
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),(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 = [(1280,1),(800,1),(800,2),(640,1),(640,2),(640,4),(320,4),(320,2),(320,1),(160,1),(120,2),(120,3),(80,6),(64,12),(64,6),(32,4),(32,8),(32,16),(32,32),(32,64)]
proportions = [(16,2),(8,2),(4,2),(2,2),(1,2)]
#proportion pln pour output final avec puredata/gem (decalage phase 32pix)
'''
proportions = [ (768,2),\
(512,4),\
(256,8),\
(128,4),(128,16),\
(64,4),(64,8),(64,16),\
(32,8),(32,16),(32,32),(32,32),(32,64),(32,128),\
(16,1),(16,4),(16,16),(16,64)]
'''
#proportions = [(512,1),(256,2),(128,4),(64,8),(64,4),(32,16),(32,32),(32,8),(16,8),(16,32),(8,64),(8,32),(8,16)]
#proportions = [(32,1),(32,2),(32,3),(32,4),(32,5),(32,6),(32,8),(32,12),(32,16),(32,24),(32,32),(32,64)]
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))
#randomCopyPosi = seq.randomCopyPosi
seq.randomCopyPosi.append(randomCopyPosi)
i+=1
# tirage au sort
#seq["choix"].append(choix_rnd)
# assignation des valeurs (paires) finales choisies
largeur = proportions[choix_rnd][0]
repeat = proportions[choix_rnd][1]
#seq["randomCopyPosi"].append(randomCopyPosi)
# pixellisation : choix de la taille du pixel = pixelSize
#pixelSizeList = [1,1,1,1,1,1,1,1,4,8]
pixelSizeList = [1,2,4,8]
pixelSizeIndex = random.randint(0,len(pixelSizeList)-1)
pixelSize = pixelSizeList[pixelSizeIndex]
cropfinal = [largeur,bas-haut]
hauteur = bas-haut
'''
haut gauche(0,0).
haut droit (largeur-1 , 0).
bas gauche (0 , hauteur-1).
bas droit (largeur-1, hauteur-1)
'''
if largeur % pixelSize != 0:
croop = largeur / pixelSize
largeur = (int(croop) + 1 ) * pixelSize
if hauteur % pixelSize != 0:
croop2 = hauteur / pixelSize
hauteur = (int(croop2) + 1 ) * pixelSize
# decoupage du sample
im5 = im2.crop((randomCopyPosi,haut,randomCopyPosi+largeur,haut+hauteur))
'''COLLAGE DU SAMPLE '''
loop = 0
while loop<repeat:
px1 = n
px2 = n + largeur
# draw = ImageDraw.Draw(im3)
''' PIXELISATION'''
im5 = im5.resize((im3.size[0]/pixelSize, im3.size[1]/pixelSize), Image.NEAREST)
im5 = im5.resize((im3.size[0]*pixelSize, im3.size[1]*pixelSize), Image.NEAREST)
im3 = im5.crop(0,0,cropfinal[0]-1,cropfinal[1]-1)
#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)")
im4.paste(im3, (px1, haut, px2, bas))
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)
# copiage
im5 = im2.crop((0,pos,im1.size[0],pos+im1.size[1]/20))
# le soulignage en blanc
draw = ImageDraw.Draw(im5)
draw.line((0, im5.size[1]-1, im5.size[0], im5.size[1]-1), fill="black")
draw.line((0, 1, im5.size[0], 1), fill="black")
# collage
im4.paste(im5, (0,pos,im1.size[0],pos+im1.size[1]/20))
# HAACHEUUR
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])
scriptpy = str(sys.argv[1])
script = scriptpy[:-3]
n = "%05d" % i
im4.save(script+"."+n+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".png",'PNG', quality=100)
#pickle.dump(seq, open("test.pickle","w"))
pickle.dump(seq, open(script+"."+n+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".pickle","w"))
#print script+"."+str(i)+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".jpg"
#millis = int(round(time.time() * 1000))
#print "millis-secondes : "+str(millis)
#obtenir les valeurs RGB des pixels de l'image
'''
from PIL import Image
im = Image.open('test.png')
pixels = list(im.getdata())
width, height = im.size
pixels = [pixels[i * width:(i + 1) * width] for i in xrange(height)]
for r in range(0, height-1) :
print "pixels = "+str(pixels[r])
print " "
print "len(pixels) = "+str(len(pixels))
print "width = "+str(width)
print "height = "+str(height)
print " "
#tintin = im.tostring( "raw", "RGBA", 0, -1)
#print "tostring = "+tintin
'''

View File

@ -34,22 +34,12 @@ allongement = 2
#im1 = Image.open(str(sys.argv[1])).convert('L')
im1 = Image.open(str(sys.argv[1]))
im2 = im1.copy()
im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
im4 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1]))
im5 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1]))
boutImage = Image.new("RGBA",(im1.size[0], im1.size[1]))
pix2 = im3.resize((im3.size[0]/2, im3.size[1]/2), Image.NEAREST)
pix4 = im3.resize((im3.size[0]/4, im3.size[1]/4), Image.NEAREST)
pix8 = im3.resize((im3.size[0]/8, im3.size[1]/8), Image.NEAREST)
pix16 = im3.resize((im3.size[0]/16, im3.size[1]/16), Image.NEAREST)
pix32 = im3.resize((im3.size[0]/32, im3.size[1]/32), Image.NEAREST)
pix64 = im3.resize((im3.size[0]/64, im3.size[1]/64), Image.NEAREST)
pix128 = im3.resize((im3.size[0]/128, im3.size[1]/128), Image.NEAREST)
pix256 = im3.resize((im3.size[0]/256, im3.size[1]/256), Image.NEAREST)
pix512 = im3.resize((im3.size[0]/512, im3.size[1]/512), Image.NEAREST)
pix1024 = im3.resize((im3.size[0]/1024, im3.size[1]/1024), Image.NEAREST)
Larg = im1.size[0]
Haut = im1.size[1]
import pickle
@ -80,14 +70,16 @@ if loadfile:
else :
seq=Sequence()
'''
for i in range(1):
'''
# 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]/16)*16
return random.randint(0, im1.size[1]/32)*32
if loadfile:
randomCoupeHauteur = seq.randomCoupeHauteur
@ -126,7 +118,26 @@ for i in range(1):
#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 = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(24,32),(24,16),(16,32),(16,16),(16,8),(16,2),(16,1),(8,24),(8,16),(8,8),(8,4),(8,2),(8,1)]
#proportions = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(32,1),(32,2),(32,4),(32,8),(32,32),(16,1),(16,2),(16,4),(16,16),(16,32)]
proportions = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(32,1),(32,2),(32,4),(32,8),(32,32),(16,1),(16,2),(16,4),(16,16),(16,32)]
#proportions = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(32,1),(32,2),(32,4),(32,8),(32,32),(16,1),(16,2),(16,4),(16,16),(16,32)]
proportions = [ (16,2),(16,4),(16,8),(16,16),(16,32),\
(32,8),(32,16),(32,32),\
(64,4),(64,8),(64,16),\
(128,2),(128,4),(128,8),\
(256,1),(256,2),(256,4),\
(512,1),(512,2),\
(1024,1),(1024,2),\
(2048,1)]
'''
proportions = [ (768,2),\
(512,4),\
(256,8),\
(128,4),(128,16),\
(64,4),(64,8),(64,16),\
(32,8),(32,16),(32,32),(32,32),(32,64),(32,128),\
(16,1),(16,4),(16,16),(16,64)]
'''
'''
1,2,4,8,16,32,64,128,256,512,1024
@ -159,8 +170,6 @@ for i in range(1):
cx1 = randomCopyPosi
cx2 = randomCopyPosi + largeur
# decoupage du sample
im3 = im2.crop((cx1,haut,cx2,bas))
#print "im3 = im2.crop : "+str(im3.size)
draw = ImageDraw.Draw(im4)
@ -168,46 +177,60 @@ for i in range(1):
loop = 0
#pixelSizeList = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,4,4,8]
pixelSizeList = [1,1,1,1,4,8,16]
pixelSizeList = [1,1,1,1,1,1,1,1,1,1,2,2,4,8,16]
pixelSizeIndex = random.randint(0,len(pixelSizeList)-1)
pixelSize = pixelSizeList[pixelSizeIndex]
#print " pixelSize = "+str(pixelSize)
cropfinal = [largeur,bas-haut]
hauteur = bas-haut
'''
haut gauche(0,0).
haut droit (largeur-1 , 0).
bas gauche (0 , hauteur-1).
bas droit (largeur-1, hauteur-1)
'''
if largeur % pixelSize != 0:
croop = largeur / pixelSize
largeur = (int(croop) + 1 ) * pixelSize
if hauteur % pixelSize != 0:
croop2 = hauteur / pixelSize
hauteur = (int(croop2) + 1 ) * pixelSize
# decoupage du sample
im5 = im2.crop((randomCopyPosi,haut,randomCopyPosi+largeur,haut+hauteur))
im3 = im2.crop((cx1,haut,cx2,bas))
''' COLLAGE DU SAMPLE
'''
boutImage = im3
while loop<repeat:
px1 = n
px2 = n + largeur
pixelSizeIndex = random.randint(0,len(pixelSizeList)-1)
pixelSize = pixelSizeList[pixelSizeIndex]
#boutImage = im3
#im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
''' PIXELISATION '''
if pixelSize > 1 :
im5 = im5.resize((im3.size[0]/pixelSize, im3.size[1]/pixelSize), Image.NEAREST)
im5 = im5.resize((im3.size[0]*pixelSize, im3.size[1]*pixelSize), Image.NEAREST)
boutImage = im3.resize((im3.size[0]/pixelSize, im3.size[1]/pixelSize), Image.ANTIALIAS)
boutImage = boutImage.resize((im3.size[0], im3.size[1]), Image.NEAREST)
im3 = im5.crop((0,0,cropfinal[0],cropfinal[1]))
while loop<repeat:
px1 = n
px2 = n + largeur
#lignes colorées de 1 pix
#draw = ImageDraw.Draw(boutImage)
#draw.line((0,0,0,4), fill="rgb(128,128,128)")
# draw.line((0,0,4,0), fill="rgb(128,128,128)")
im4.paste(boutImage, (px1, haut, px2, bas))
draw = ImageDraw.Draw(im3)
draw.line((0, 0, largeur-1, 0), fill="rgb(255,255,255)")
draw.line((largeur-1, 0, largeur-1, bas-haut), fill="rgb(255,255,255)")
pix2 pix4 pix8 pix16 pix32 pix64 pix128 pix256 pix512 pix1024
'''
draw = ImageDraw.Draw(im4)
draw.line((px1-2, haut, px1+2, haut), fill="rgb(0,0,0)")
draw.line((px1, haut-2, px1, haut+2), fill="rgb(0,0,0)")
draw.line((px1-2, bas-1, px1+2, bas-1), fill="rgb(0,0,0)")
draw.line((px1, bas-2, px1, bas+2), fill="rgb(0,0,0)")
'''
im4.paste(im3, (px1, haut, px2, bas))
n = n + largeur
loop = loop + 1
@ -237,7 +260,8 @@ for i in range(1):
#chemin de l'image : str(sys.argv[1])
scriptpy = str(sys.argv[1])
script = scriptpy[:-3]
n = "%05d" % i
#n = "%05d" % i
n = "1.1"
im4.save(script+"."+n+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".png",'PNG', quality=100)
pickle.dump(seq, open(script+"."+n+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".pickle","w"))

271
hacheur.py Normal file
View File

@ -0,0 +1,271 @@
#!/usr/bin/python
# coding: utf-8
# haacheuur 0.24
# port industriel de port la nouvelle - couleur - 60cm*30cm
# image source : pln.jpg
# image obtenue : pln..20150910-11h59m53s.jpg
import sys
import Image
import random
import os
import ImageDraw
import ImageFont
import ImageFilter
from time import gmtime, strftime
import time
# modifs du 30/10/2013
import ImageEnhance
'''
multiples 1024 : 1024 2048 3072 4096 5120 6144 7168 8192 9216 10240
multiples 768 : 768 1536 2304 3072 3840 4608 5376 6144 6912 7680 8448 9216 9984 10752
'''
#rapport d'allongement de la nouvelle image par rapport à la largeur de l'image originale
allongement = 2
#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')
im1 = Image.open(str(sys.argv[1]))
im2 = im1.copy()
im4 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1]))
im5 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1]))
boutImage = Image.new("RGBA",(im1.size[0], im1.size[1]))
Larg = im1.size[0]
Haut = im1.size[1]
import pickle
loadfile = False
class Sequence:
def __init__(s):
randomCoupeHauteur = []
s.randomCopyPosi =[]
s.proportions=[]
s.choix=[]
s.sizeOutput=None
s.sizeInput=None
"""
seq = dict()
seq["randomCoupeHauteur"] = []
seq["randomCopyPosi"] = []
seq["proportions"] = []
seq["choix"] = []
seq["sizeOutput"]= im4.size
seq["sizeInput"] = im1.size
"""
if loadfile:
seq=pickle.load(open("test.pickle"))
else :
seq=Sequence()
'''
for i in range(1):
'''
# 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]/32)*32
if loadfile:
randomCoupeHauteur = seq.randomCoupeHauteur
else:
randomCoupeHauteur = [0, \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
randHaut(),randHaut(),randHaut(),randHaut(), \
im1.size[1]]
# rangement des valeurs des plus petites au plus grandes
randomCoupeHauteur.sort()
seq.randomCoupeHauteur = randomCoupeHauteur
# les hachures
def Hacheur(haut, bas) :
n=0
i=0
#!!!!!!!!!!
while n<im4.size[0] :
if loadfile:
proportions = seq.proportions
choix_rnd = seq.choix[i]
randomCopyPosi = seq.randomCopyPosi[i]
else:
'''
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 = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(24,32),(24,16),(16,32),(16,16),(16,8),(16,2),(16,1),(8,24),(8,16),(8,8),(8,4),(8,2),(8,1)]
#proportions = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(32,1),(32,2),(32,4),(32,8),(32,32),(16,1),(16,2),(16,4),(16,16),(16,32)]
#proportions = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(32,1),(32,2),(32,4),(32,8),(32,32),(16,1),(16,2),(16,4),(16,16),(16,32)]
proportions = [ (16,2),(16,4),(16,8),(16,16),(16,32),\
(32,8),(32,16),(32,32),\
(64,4),(64,8),(64,16),\
(128,2),(128,4),(128,8),\
(256,1),(256,2),(256,4),\
(512,1),(512,2),\
(1024,1),(1024,2),\
(2048,1)]
'''
proportions = [ (768,2),\
(512,4),\
(256,8),\
(128,4),(128,16),\
(64,4),(64,8),(64,16),\
(32,8),(32,16),(32,32),(32,32),(32,64),(32,128),\
(16,1),(16,4),(16,16),(16,64)]
'''
'''
1,2,4,8,16,32,64,128,256,512,1024
'''
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))
#randomCopyPosi = seq.randomCopyPosi
seq.randomCopyPosi.append(randomCopyPosi)
i+=1
# tirage au sort
#seq["choix"].append(choix_rnd)
# assignation des valeurs (paires) finales choisies
largeur = proportions[choix_rnd][0]
repeat = proportions[choix_rnd][1]
#seq["randomCopyPosi"].append(randomCopyPosi)
cx1 = randomCopyPosi
cx2 = randomCopyPosi + largeur
#print "im3 = im2.crop : "+str(im3.size)
draw = ImageDraw.Draw(im4)
loop = 0
#pixelSizeList = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,4,4,8]
pixelSizeList = [1,1,1,1,1,1,1,1,1,1,2,2,4,8,16]
pixelSizeIndex = random.randint(0,len(pixelSizeList)-1)
pixelSize = pixelSizeList[pixelSizeIndex]
#print " pixelSize = "+str(pixelSize)
cropfinal = [largeur,bas-haut]
hauteur = bas-haut
'''
haut gauche(0,0).
haut droit (largeur-1 , 0).
bas gauche (0 , hauteur-1).
bas droit (largeur-1, hauteur-1)
'''
if largeur % pixelSize != 0:
croop = largeur / pixelSize
largeur = (int(croop) + 1 ) * pixelSize
if hauteur % pixelSize != 0:
croop2 = hauteur / pixelSize
hauteur = (int(croop2) + 1 ) * pixelSize
# decoupage du sample
im5 = im2.crop((randomCopyPosi,haut,randomCopyPosi+largeur,haut+hauteur))
im3 = im2.crop((cx1,haut,cx2,bas))
''' COLLAGE DU SAMPLE
'''
#boutImage = im3
#im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
''' PIXELISATION '''
if pixelSize > 1 :
im5 = im5.resize((im3.size[0]/pixelSize, im3.size[1]/pixelSize), Image.NEAREST)
im5 = im5.resize((im3.size[0]*pixelSize, im3.size[1]*pixelSize), Image.NEAREST)
im3 = im5.crop((0,0,cropfinal[0],cropfinal[1]))
while loop<repeat:
px1 = n
px2 = n + largeur
#lignes colorées de 1 pix
#draw = ImageDraw.Draw(boutImage)
#draw.line((0,0,0,4), fill="rgb(128,128,128)")
draw = ImageDraw.Draw(im3)
draw.line((0, 0, largeur-1, 0), fill="rgb(255,255,255)")
draw.line((largeur-1, 0, largeur-1, bas-haut), fill="rgb(255,255,255)")
im4.paste(im3, (px1, haut, px2, bas))
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)
# copiage
im5 = im2.crop((0,pos,im1.size[0],pos+im1.size[1]/20))
# le soulignage en blanc
draw = ImageDraw.Draw(im5)
draw.line((0, im5.size[1]-1, im5.size[0], im5.size[1]-1), fill="black")
draw.line((0, 1, im5.size[0], 1), fill="black")
# collage
im4.paste(im5, (0,pos,im1.size[0],pos+im1.size[1]/20))
# HAACHEUUR
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])
scriptpy = str(sys.argv[1])
script = scriptpy[:-3]
#n = "%05d" % i
n = "1.1"
im4.save(script+"."+n+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".png",'PNG', quality=100)
pickle.dump(seq, open(script+"."+n+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".pickle","w"))
#print script+"."+str(i)+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".jpg"
#millis = int(round(time.time() * 1000))
#print "millis-secondes : "+str(millis)

15010
test.pickle

File diff suppressed because it is too large Load Diff