comparison transformations/PermutPixel.py @ 78:9936c4886299

Mise a niveau specifications parametres deterministes, bruitage moins aggressif et transformations toutes pareilles tant qu'on ne rappelle pas regenerate_parameters()
author SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
date Wed, 10 Feb 2010 14:51:18 -0500
parents 48a21d19b8eb
children 6696391273ab
comparison
equal deleted inserted replaced
77:aee278ebc827 78:9936c4886299
19 def __init__(self): 19 def __init__(self):
20 self.nombre=10 #Le nombre de pixels a permuter 20 self.nombre=10 #Le nombre de pixels a permuter
21 self.proportion=0.3 21 self.proportion=0.3
22 22
23 def get_settings_names(self): 23 def get_settings_names(self):
24 return []
25
26 def get_settings_name_determined_by_complexity(self):
24 return ['nombre'] 27 return ['nombre']
25 28
26 def regenerate_parameters(self, complexity): 29 def regenerate_parameters(self, complexity):
27 self.proportion=float(complexity) 30 self.proportion=float(complexity)/3
28 self.nombre=int(256*self.proportion)*4 #Par multiple de 4 (256=1024/4) 31 self.nombre=int(256*self.proportion)*4 #Par multiple de 4 (256=1024/4)
32 self.echantillon=random.sample(xrange(0,1024),self.nombre) #Les pixels qui seront permutes
29 return self._get_current_parameters() 33 return self._get_current_parameters()
30 34
31 def _get_current_parameters(self): 35 def _get_current_parameters(self):
32 return [] 36 return []
33 37
35 return [int(complexity*256)*4] 39 return [int(complexity*256)*4]
36 40
37 def transform_image(self, image): 41 def transform_image(self, image):
38 image=image.reshape(1024,1) 42 image=image.reshape(1024,1)
39 temp=0 #variable temporaire 43 temp=0 #variable temporaire
40 #constitution de l'echantillon 44
41 echantillon=random.sample(xrange(0,1024),self.nombre) 45 for i in xrange(0,self.nombre,4): #Par bonds de 4
42 for i in xrange(0,self.nombre,4):
43 #gauche 46 #gauche
44 if echantillon[i] > 0: 47 if self.echantillon[i] > 0:
45 temp=image[echantillon[i]-1] 48 temp=image[self.echantillon[i]-1]
46 image[echantillon[i]-1]=image[echantillon[i]] 49 image[self.echantillon[i]-1]=image[self.echantillon[i]]
47 image[echantillon[i]]=temp 50 image[self.echantillon[i]]=temp
48 #droite 51 #droite
49 if echantillon[i+1] < 1023: 52 if self.echantillon[i+1] < 1023:
50 temp=image[echantillon[i+1]+1] 53 temp=image[self.echantillon[i+1]+1]
51 image[echantillon[i+1]+1]=image[echantillon[i+1]] 54 image[self.echantillon[i+1]+1]=image[self.echantillon[i+1]]
52 image[echantillon[i+1]]=temp 55 image[self.echantillon[i+1]]=temp
53 #haut 56 #haut
54 if echantillon[i+2] > 31: 57 if self.echantillon[i+2] > 31:
55 temp=image[echantillon[i+2]-32] 58 temp=image[self.echantillon[i+2]-32]
56 image[echantillon[i+2]-32]=image[echantillon[i+2]] 59 image[self.echantillon[i+2]-32]=image[self.echantillon[i+2]]
57 image[echantillon[i+2]]=temp 60 image[self.echantillon[i+2]]=temp
58 #bas 61 #bas
59 if echantillon[i+3] < 992: 62 if self.echantillon[i+3] < 992:
60 temp=image[echantillon[i+3]+32] 63 temp=image[self.echantillon[i+3]+32]
61 image[echantillon[i+3]+32]=image[echantillon[i+3]] 64 image[self.echantillon[i+3]+32]=image[self.echantillon[i+3]]
62 image[echantillon[i+3]]=temp 65 image[self.echantillon[i+3]]=temp
63 66
64 67
65 return image.reshape((32,32)) 68 return image.reshape((32,32))
66 69
67 70
89 92
90 if __name__ == '__main__': 93 if __name__ == '__main__':
91 from pylearn.io import filetensor as ft 94 from pylearn.io import filetensor as ft
92 import pylab 95 import pylab
93 for i in xrange(0,5): 96 for i in xrange(0,5):
94 _test(0.5) 97 _test(0)
95 98
96 99