Mercurial > ift6266
comparison transformations/BruitGauss.py @ 111:259439a4f9e7
Changed a bit the code for BruitGauss.py for simplicity
author | Xavier Glorot <glorotxa@iro.umontreal.ca> |
---|---|
date | Tue, 16 Feb 2010 17:24:21 -0500 |
parents | 313c249d638e |
children | fa35d9ecf664 |
comparison
equal
deleted
inserted
replaced
110:93b4b84d86cf | 111:259439a4f9e7 |
---|---|
33 self.grandeurmax = 20 | 33 self.grandeurmax = 20 |
34 self.sigmamax = 6.0 | 34 self.sigmamax = 6.0 |
35 self.regenerate_parameters(complexity) | 35 self.regenerate_parameters(complexity) |
36 | 36 |
37 def get_settings_names(self): | 37 def get_settings_names(self): |
38 return ['nb_chng','sigma_gauss','grandeur','effectuer'] | 38 return ['nb_chng','sigma_gauss','grandeur'] |
39 | 39 |
40 def regenerate_parameters(self, complexity): | 40 def regenerate_parameters(self, complexity): |
41 self.nb_chng=3+int(numpy.random.rand()*self.nb_chngmax*complexity) | 41 self.effectuer =numpy.random.binomial(1,0.25) ##### On a 25% de faire un bruit ##### |
42 | |
42 | 43 |
43 if float(complexity) > 0: | 44 if self.effectuer and complexity > 0: |
45 self.nb_chng=3+int(numpy.random.rand()*self.nb_chngmax*complexity) | |
44 self.sigma_gauss=2.0 + numpy.random.rand()*self.sigmamax*complexity | 46 self.sigma_gauss=2.0 + numpy.random.rand()*self.sigmamax*complexity |
45 self.grandeur=12+int(numpy.random.rand()*self.grandeurmax*complexity) | 47 self.grandeur=12+int(numpy.random.rand()*self.grandeurmax*complexity) |
46 self.effectuer =numpy.random.binomial(1,0.25) ##### On a 25% de faire un bruit ##### | 48 #creation du noyau gaussien |
49 self.gauss=numpy.zeros((self.grandeur,self.grandeur)) | |
50 x0 = y0 = self.grandeur/2.0 | |
51 for i in xrange(self.grandeur): | |
52 for j in xrange(self.grandeur): | |
53 self.gauss[i,j]=numpy.exp(-((i-x0)**2 + (j-y0)**2) / self.sigma_gauss**2) | |
54 #creation de la fenetre de moyennage | |
55 self.moy=numpy.zeros((self.grandeur,self.grandeur)) | |
56 x0 = y0 = self.grandeur/2 | |
57 for i in xrange(0,self.grandeur): | |
58 for j in xrange(0,self.grandeur): | |
59 self.moy[i,j]=((numpy.sqrt(2*(self.grandeur/2.0)**2) -\ | |
60 numpy.sqrt(numpy.abs(i-self.grandeur/2.0)**2+numpy.abs(j-self.grandeur/2.0)**2))/numpy.sqrt((self.grandeur/2.0)**2))**5 | |
47 else: | 61 else: |
48 self.effectuer = 0 | |
49 self.sigma_gauss = 1 # eviter division par 0 | 62 self.sigma_gauss = 1 # eviter division par 0 |
50 self.grandeur=1 | 63 self.grandeur=1 |
51 #Un peu de paranoia ici, mais on ne sait jamais | 64 self.nb_chng = 0 |
65 self.effectuer = 0 | |
52 | 66 |
53 #creation du noyau gaussien | |
54 self.gauss=numpy.zeros((self.grandeur,self.grandeur)) | |
55 x0 = y0 = self.grandeur/2.0 | |
56 for i in xrange(self.grandeur): | |
57 for j in xrange(self.grandeur): | |
58 self.gauss[i,j]=numpy.exp(-((i-x0)**2 + (j-y0)**2) / self.sigma_gauss**2) | |
59 #creation de la fenetre de moyennage | |
60 self.moy=numpy.zeros((self.grandeur,self.grandeur)) | |
61 x0 = y0 = self.grandeur/2 | |
62 for i in xrange(0,self.grandeur): | |
63 for j in xrange(0,self.grandeur): | |
64 self.moy[i,j]=((numpy.sqrt(2*(self.grandeur/2.0)**2) - numpy.sqrt(numpy.abs(i-self.grandeur/2.0)**2+numpy.abs(j-self.grandeur/2.0)**2))/\ | |
65 numpy.sqrt((self.grandeur/2.0)**2))**5 | |
66 | |
67 return self._get_current_parameters() | 67 return self._get_current_parameters() |
68 | 68 |
69 def _get_current_parameters(self): | 69 def _get_current_parameters(self): |
70 return [self.nb_chng,self.sigma_gauss,self.grandeur,self.effectuer] | 70 return [self.nb_chng,self.sigma_gauss,self.grandeur] |
71 | 71 |
72 | 72 |
73 def transform_image(self, image): | 73 def transform_image(self, image): |
74 if self.effectuer == 0: | 74 if self.effectuer == 0: |
75 return image | 75 return image |