123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #!/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()
- im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
- im4 = 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
-
- 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]/16)*16
-
- 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)]
-
- '''
- 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
- # decoupage du sample
- im3 = im2.crop((cx1,haut,cx2,bas))
- #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,4,8,16]
-
- #print " pixelSize = "+str(pixelSize)
-
-
- ''' COLLAGE DU SAMPLE
- '''
-
- boutImage = im3
-
- while loop<repeat:
-
- px1 = n
- px2 = n + largeur
-
- pixelSizeIndex = random.randint(0,len(pixelSizeList)-1)
- pixelSize = pixelSizeList[pixelSizeIndex]
-
- ''' PIXELISATION '''
-
- boutImage = im3.resize((im3.size[0]/pixelSize, im3.size[1]/pixelSize), Image.ANTIALIAS)
- boutImage = boutImage.resize((im3.size[0], im3.size[1]), Image.NEAREST)
-
- #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))
-
- 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)")
- '''
-
- 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(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)
|