ajout de video2d.py, script applatissant une séquence vidéo en 1 bitmap très large
This commit is contained in:
		
							parent
							
								
									3ec643b1a0
								
							
						
					
					
						commit
						adc56b0f75
					
				
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,2 +1,5 @@ | ||||
| pln | ||||
| pylone3 | ||||
| screen | ||||
| test | ||||
| tth | ||||
|  | ||||
							
								
								
									
										110
									
								
								hacheuur.py
									
									
									
									
									
								
							
							
						
						
									
										110
									
								
								hacheuur.py
									
									
									
									
									
								
							| @ -6,6 +6,14 @@ | ||||
| # 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 | ||||
| @ -16,19 +24,25 @@ 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 | ||||
| 
 | ||||
| #ouvertrure de l'image source et conversion en mode couleur 1bit | ||||
| #ouverture 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() | ||||
| 
 | ||||
| #rapport d'allongement de la nouvelle image par rapport à la largeur de l'image originale | ||||
| allongement = 4 | ||||
| allongement = 8 | ||||
| 
 | ||||
| im3 = 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] | ||||
| @ -48,30 +62,30 @@ class Sequence: | ||||
| """ | ||||
| seq = dict() | ||||
| seq["randomCoupeHauteur"] = [] | ||||
| seq["randomCopyPosi"] = []  | ||||
| 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(4): | ||||
| 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(), \ | ||||
| @ -86,25 +100,44 @@ for i in range(4): | ||||
| 		# 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),(64,16),(24,32),(8,24),(8,16)] | ||||
| 				#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 = [(256,1),(160,1),(120,2),(120,3),(80,6),(64,12),(24,18),(8,24),(8,16)] | ||||
| 
 | ||||
| 				#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) | ||||
| @ -112,41 +145,42 @@ for i in range(4): | ||||
| 				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 | ||||
| 
 | ||||
| 			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 | ||||
| 			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) | ||||
| 			 | ||||
| 			pixelSizeList = [1,1,1,1,1,1,1,1,4,8] | ||||
| 			#pixelSizeList = [1] | ||||
| 			pixelSizeIndex = random.randint(0,len(pixelSizeList)-1) | ||||
| 			pixelSize = pixelSizeList[pixelSizeIndex] | ||||
| 			''' | ||||
| 			print " pixelSize = "+str(pixelSize) | ||||
| 			''' | ||||
| 			 | ||||
| 			''' COLLAGE DU SAMPLE | ||||
| 			''' | ||||
| @ -162,9 +196,11 @@ for i in range(4): | ||||
| 				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)") | ||||
| 				 | ||||
| @ -193,8 +229,9 @@ for i in range(4): | ||||
| 	for j in range(len(randomCoupeHauteur)-1): | ||||
| 		Hacheur(randomCoupeHauteur[j], randomCoupeHauteur[j+1]) | ||||
| 	 | ||||
| 	''' SAUVEGARDE | ||||
| 	''' SAUVEGARDE	 | ||||
| 	''' | ||||
| 	 | ||||
| 	# CTRL + S | ||||
| 	#chemin du script	: scriptpy = sys.argv[0] | ||||
| 	#chemin de l'image	: str(sys.argv[1]) | ||||
| @ -207,4 +244,27 @@ for i in range(4): | ||||
| 	#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 | ||||
| ''' | ||||
|  | ||||
							
								
								
									
										13541
									
								
								test.pickle
									
									
									
									
									
								
							
							
						
						
									
										13541
									
								
								test.pickle
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										44
									
								
								video2d.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								video2d.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | ||||
| #!/usr/bin/python | ||||
| # coding: utf-8 | ||||
| 
 | ||||
| import sys | ||||
| import Image | ||||
| 
 | ||||
| ''' | ||||
| im1 = Image.open(str(sys.argv[1])) | ||||
| width, height = im1.size | ||||
| print  | ||||
| print "width  =% 5.2i" % width | ||||
| print "height =% 5.2i" % height | ||||
| print | ||||
| allongement = 8 | ||||
| im4 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1])) | ||||
| 
 | ||||
| for x in range(1,allongement+1): | ||||
|     print('%03.1i' % x) | ||||
| ''' | ||||
| 
 | ||||
| 
 | ||||
| index = 1 | ||||
| allongement = 300      #4818 | ||||
| 
 | ||||
| 
 | ||||
| im1 = Image.open("./drone/img001.jpg") | ||||
| im2 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1])) | ||||
| 
 | ||||
| largeur = im1.size[0] | ||||
| 
 | ||||
| for x in range(0,allongement/10): | ||||
| 	position = 0 | ||||
| 	 | ||||
| 	for y in range(1,11): | ||||
| 		im1 = Image.open("./drone/img%03.1i.jpg" % y) | ||||
| 		im2.paste(im1, (position,0)) | ||||
| 		#print position | ||||
| 		#print("./drone/img%03.1i.jpg" % x) | ||||
| 		position = position + largeur | ||||
| 		 | ||||
| 	scriptpy = str(sys.argv[1]) | ||||
| 	script = scriptpy[:-3] | ||||
| 	im2.save(script+"_"+str(x)+".png",'PNG', quality=100) | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user