pg waz herre :p
This commit is contained in:
119
hacheuur.py
119
hacheuur.py
@@ -4,7 +4,7 @@
|
||||
# haacheuur 0.24
|
||||
# port industriel de port la nouvelle - couleur - 60cm*30cm
|
||||
# image source : pln.jpg
|
||||
# image rendue : pln..20150910-11h59m53s.jpg
|
||||
# image obtenue : pln..20150910-11h59m53s.jpg
|
||||
|
||||
import sys
|
||||
import Image
|
||||
@@ -19,61 +19,115 @@ import time
|
||||
# modifs du 30/10/2013
|
||||
import ImageEnhance
|
||||
|
||||
#ouvertrure de l'image source et conversion en mode 1bit
|
||||
#ouvertrure de l'image source et conversion en mode couleur 1bit
|
||||
im1 = Image.open(str(sys.argv[1])).convert('1')
|
||||
im2 = im1.copy()
|
||||
|
||||
#rapport d'allongement de la nouvelle image par rapport à la largeur de l'image originale
|
||||
allongement = 1
|
||||
allongement = 4
|
||||
|
||||
im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
|
||||
im4 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1]))
|
||||
|
||||
Larg = im1.size[0]
|
||||
Haut = im1.size[1]
|
||||
import pickle
|
||||
|
||||
for i in range(10):
|
||||
# nombre aleatoire compris dans les limites de l'image
|
||||
def randHaut(): return random.randint(0, im1.size[1])
|
||||
loadfile = True
|
||||
|
||||
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 :)
|
||||
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(), \
|
||||
im1.size[1]]
|
||||
|
||||
# rangement des valeurs des plus petites au plus grandes
|
||||
randomCoupeHauteur.sort()
|
||||
|
||||
# DEBUG
|
||||
liste = []
|
||||
# nombre aleatoire compris dans les limites de l'image
|
||||
def randHaut():
|
||||
return random.randint(0, im1.size[1])
|
||||
|
||||
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] :
|
||||
randomListe = [(1280,2),(640,4),(320,5),(240,4),(160,6),(120,4),(120,8),(80,16),(60,16),(20,32),(8,24),(8,16),(5,64),(3,24),(2,24),(1,128),(1,64),(1,6)]
|
||||
|
||||
choix = 0
|
||||
if loadfile:
|
||||
proportions = seq.proportions
|
||||
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)]
|
||||
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)
|
||||
|
||||
|
||||
# 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
|
||||
randomFacteur = random.randint(0, len(randomListe)-1)
|
||||
|
||||
|
||||
#seq["choix"].append(choix_rnd)
|
||||
|
||||
# assignation des valeurs (paires) finales choisies
|
||||
randomCopyLargFinal = randomListe[randomFacteur][0]
|
||||
repeat = randomListe[randomFacteur][1]
|
||||
largeur = proportions[choix_rnd][0]
|
||||
repeat = proportions[choix_rnd][1]
|
||||
|
||||
# positionnement de la copie, aleatoirement, entre 0 et la largeur totale de l'image
|
||||
randomCopyPosi = random.randint(0, (im1.size[0]-randomCopyLargFinal))
|
||||
|
||||
#seq["randomCopyPosi"].append(randomCopyPosi)
|
||||
|
||||
cx1 = randomCopyPosi
|
||||
cx2 = randomCopyPosi + randomCopyLargFinal
|
||||
cx2 = randomCopyPosi + largeur
|
||||
# decoupage du sample
|
||||
im3 = im2.crop((cx1,haut,cx2,bas))
|
||||
|
||||
@@ -83,7 +137,7 @@ for i in range(10):
|
||||
#collage, n fois, du sample
|
||||
while loop<repeat:
|
||||
px1 = n
|
||||
px2 = n + randomCopyLargFinal
|
||||
px2 = n + largeur
|
||||
|
||||
draw = ImageDraw.Draw(im3)
|
||||
|
||||
@@ -92,7 +146,7 @@ for i in range(10):
|
||||
|
||||
im4.paste(im3, (px1, haut, px2, bas))
|
||||
|
||||
n = n + randomCopyLargFinal
|
||||
n = n + largeur
|
||||
loop = loop + 1
|
||||
|
||||
def TrancheHorizontale() :
|
||||
@@ -113,10 +167,6 @@ for i in range(10):
|
||||
for j in range(len(randomCoupeHauteur)-1):
|
||||
Hacheur(randomCoupeHauteur[j], randomCoupeHauteur[j+1])
|
||||
|
||||
# DEBUG
|
||||
#print liste
|
||||
#print sorted(set(liste),key=liste.count)
|
||||
|
||||
# CTRL + S
|
||||
#chemin du script : scriptpy = sys.argv[0]
|
||||
#chemin de l'image : str(sys.argv[1])
|
||||
@@ -124,6 +174,7 @@ for i in range(10):
|
||||
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"))
|
||||
|
||||
#print script+"."+str(i)+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".jpg"
|
||||
#millis = int(round(time.time() * 1000))
|
||||
|
||||
Reference in New Issue
Block a user