annotate data_generation/transformations/BruitGauss.py @ 167:1f5937e9e530

More moves - transformations into data_generation, added "deep" folder
author Dumitru Erhan <dumitru.erhan@gmail.com>
date Fri, 26 Feb 2010 14:15:38 -0500
parents transformations/BruitGauss.py@7640cb31cf1f
children d5b2b6397a5a
rev   line source
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
1 #!/usr/bin/python
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
2 # coding: utf-8
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
3
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
4 '''
62
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
5 Ajout de bruit gaussien dans les donnees. A chaque iteration, un bruit poivre
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
6 et sel est ajoute, puis un lissage gaussien autour de ce point est ajoute.
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
7 On fait un nombre d'iteration = 1024*complexity/25 ce qui equivaud
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
8 a complexity/25 des points qui recoivent le centre du noyau gaussien.
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
9 Il y en a beaucoup moins que le bruit poivre et sel, car la transformation
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
10 est plutôt aggressive et touche beaucoup de pixels autour du centre
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
11
62
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
12 La grandeur de la gaussienne ainsi que son ecart type sont definit par complexity
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
13 et par une composante aleatoire normale.
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
14
89
cc641ee75d3b Il y a maintenant 25% de proba d'effectuer le bruitage
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 62
diff changeset
15 On a 25 % de chances d'effectuer le bruitage
cc641ee75d3b Il y a maintenant 25% de proba d'effectuer le bruitage
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 62
diff changeset
16
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
17 Ce fichier prend pour acquis que les images sont donnees une a la fois
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
18 sous forme de numpy.array de 1024 (32 x 32) valeurs entre 0 et 1.
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
19
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
20 Sylvain Pannetier Lebeuf dans le cadre de IFT6266, hiver 2010
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
21
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
22 '''
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
23
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
24 import numpy
149
fa35d9ecf664 Rajout d'un seed random et d'une fonction get_seed.Aussi, import random enleve car non necessaire
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 111
diff changeset
25 #import random
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
26 import scipy
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
27 from scipy import ndimage
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
28
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
29 class BruitGauss():
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
30
149
fa35d9ecf664 Rajout d'un seed random et d'une fonction get_seed.Aussi, import random enleve car non necessaire
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 111
diff changeset
31 def __init__(self,complexity=1,seed=6378):
96
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
32 self.nb_chngmax =10 #Le nombre de pixels changes. Seulement pour fin de calcul
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
33 self.grandeurmax = 20
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
34 self.sigmamax = 6.0
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
35 self.regenerate_parameters(complexity)
149
fa35d9ecf664 Rajout d'un seed random et d'une fonction get_seed.Aussi, import random enleve car non necessaire
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 111
diff changeset
36 self.seed=seed
fa35d9ecf664 Rajout d'un seed random et d'une fonction get_seed.Aussi, import random enleve car non necessaire
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 111
diff changeset
37
155
7640cb31cf1f Enlevé les re-seed constants, interfère avec les autres modules
boulanni <nicolas_boulanger@hotmail.com>
parents: 149
diff changeset
38 #numpy.random.seed(self.seed)
149
fa35d9ecf664 Rajout d'un seed random et d'une fonction get_seed.Aussi, import random enleve car non necessaire
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 111
diff changeset
39
fa35d9ecf664 Rajout d'un seed random et d'une fonction get_seed.Aussi, import random enleve car non necessaire
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 111
diff changeset
40 def get_seed(self):
fa35d9ecf664 Rajout d'un seed random et d'une fonction get_seed.Aussi, import random enleve car non necessaire
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 111
diff changeset
41 return self.seed
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
42
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
43 def get_settings_names(self):
111
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
44 return ['nb_chng','sigma_gauss','grandeur']
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
45
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
46 def regenerate_parameters(self, complexity):
111
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
47 self.effectuer =numpy.random.binomial(1,0.25) ##### On a 25% de faire un bruit #####
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
48
89
cc641ee75d3b Il y a maintenant 25% de proba d'effectuer le bruitage
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 62
diff changeset
49
111
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
50 if self.effectuer and complexity > 0:
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
51 self.nb_chng=3+int(numpy.random.rand()*self.nb_chngmax*complexity)
96
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
52 self.sigma_gauss=2.0 + numpy.random.rand()*self.sigmamax*complexity
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
53 self.grandeur=12+int(numpy.random.rand()*self.grandeurmax*complexity)
111
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
54 #creation du noyau gaussien
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
55 self.gauss=numpy.zeros((self.grandeur,self.grandeur))
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
56 x0 = y0 = self.grandeur/2.0
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
57 for i in xrange(self.grandeur):
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
58 for j in xrange(self.grandeur):
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
59 self.gauss[i,j]=numpy.exp(-((i-x0)**2 + (j-y0)**2) / self.sigma_gauss**2)
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
60 #creation de la fenetre de moyennage
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
61 self.moy=numpy.zeros((self.grandeur,self.grandeur))
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
62 x0 = y0 = self.grandeur/2
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
63 for i in xrange(0,self.grandeur):
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
64 for j in xrange(0,self.grandeur):
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
65 self.moy[i,j]=((numpy.sqrt(2*(self.grandeur/2.0)**2) -\
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
66 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
62
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
67 else:
106
313c249d638e Correction bug division par zéro dans BruitGauss.py
boulanni <nicolas_boulanger@hotmail.com>
parents: 99
diff changeset
68 self.sigma_gauss = 1 # eviter division par 0
62
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
69 self.grandeur=1
111
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
70 self.nb_chng = 0
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
71 self.effectuer = 0
62
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
72
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
73 return self._get_current_parameters()
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
74
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
75 def _get_current_parameters(self):
111
259439a4f9e7 Changed a bit the code for BruitGauss.py for simplicity
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 106
diff changeset
76 return [self.nb_chng,self.sigma_gauss,self.grandeur]
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
77
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
78
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
79 def transform_image(self, image):
89
cc641ee75d3b Il y a maintenant 25% de proba d'effectuer le bruitage
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 62
diff changeset
80 if self.effectuer == 0:
cc641ee75d3b Il y a maintenant 25% de proba d'effectuer le bruitage
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 62
diff changeset
81 return image
62
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
82 image=image.reshape((32,32))
96
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
83 filtered_image = ndimage.convolve(image,self.gauss,mode='constant')
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
84 assert image.shape == filtered_image.shape
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
85 filtered_image = (filtered_image - filtered_image.min() + image.min()) / (filtered_image.max() - filtered_image.min() + image.min()) * image.max()
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
86
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
87 #construction of the moyennage Mask
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
88 Mask = numpy.zeros((32,32))
62
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
89
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
90 for i in xrange(0,self.nb_chng):
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
91 x_bruit=int(numpy.random.randint(0,32))
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
92 y_bruit=int(numpy.random.randint(0,32))
96
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
93 offsetxmin = 0
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
94 offsetxmax = 0
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
95 offsetymin = 0
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
96 offsetymax = 0
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
97 if x_bruit < self.grandeur / 2:
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
98 offsetxmin = self.grandeur / 2 - x_bruit
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
99 if 32-x_bruit < numpy.ceil(self.grandeur / 2.0):
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
100 offsetxmax = numpy.ceil(self.grandeur / 2.0) - (32-x_bruit)
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
101 if y_bruit < self.grandeur / 2:
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
102 offsetymin = self.grandeur / 2 - y_bruit
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
103 if 32-y_bruit < numpy.ceil(self.grandeur / 2.0):
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
104 offsetymax = numpy.ceil(self.grandeur / 2.0) - (32-y_bruit)
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
105 Mask[x_bruit - self.grandeur/2 + offsetxmin : x_bruit + numpy.ceil(self.grandeur/2.0) - offsetxmax,\
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
106 y_bruit - self.grandeur/2 + offsetymin : y_bruit + numpy.ceil(self.grandeur/2.0)- offsetymax] +=\
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
107 self.moy[offsetxmin:self.grandeur - offsetxmax,offsetymin:self.grandeur - offsetymax]
62
bab98bb47616 Correction majeure. Auparavant, le lissage gaussien etait global avec une seule gaussienne. Maintenant, le lissage gaussien est local. Un bruit correle est rajoute sur l'image
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents: 38
diff changeset
108
96
17fabd74dd2b Changed behavior of gaussian noise to apply a gauss filter with a random sigma, and then select some point of the image to be averaged with it
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 89
diff changeset
109 return numpy.asarray((image + filtered_image*Mask)/(Mask+1),dtype='float32')
38
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
110
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
111 #---TESTS---
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
112
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
113 def _load_image():
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
114 f = open('/home/sylvain/Dropbox/Msc/IFT6266/donnees/lower_test_data.ft') #Le jeu de donnees est en local.
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
115 d = ft.read(f)
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
116 w=numpy.asarray(d[0])
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
117 return (w/255.0).astype('float')
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
118
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
119 def _test(complexite):
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
120 img=_load_image()
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
121 transfo = BruitGauss()
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
122 pylab.imshow(img.reshape((32,32)))
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
123 pylab.show()
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
124 print transfo.get_settings_names()
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
125 print transfo.regenerate_parameters(complexite)
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
126
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
127 img_trans=transfo.transform_image(img)
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
128
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
129 pylab.imshow(img_trans.reshape((32,32)))
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
130 pylab.show()
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
131
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
132
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
133 if __name__ == '__main__':
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
134 from pylearn.io import filetensor as ft
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
135 import pylab
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
136 _test(0.5)
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
137
349d8dc9504c Ajout de bruit poivre et sel, puis filtre gaussien. Parametres deterministes par rapport a complexity. Compatible testmod.py
SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
parents:
diff changeset
138