9 _matrices_DWT = {'A1' : None,
10 'H1' : None, 'D1' : None, 'V1' : None,
12 'H2' : None, 'D2' : None, 'V2' : None,
14 'H3' : None, 'D3' : None, 'V3' : None
17 def __init__(self, hote, famille = 'db1'):
21 self._hote = im.open(hote)
23 print "--------",self._hote.mode
24 self._hote_marque = im.new(self._hote.mode,
27 self._hote_marque.putdata(self._hote.getdata())
29 self._matrice_hote = array(self._hote.getdata()).\
30 reshape(self._hote.size)
32 self._famille = famille
38 def _get_matrices(self):
40 A1,(H1,V1,D1) = pywt.wavedec2\
45 self._matrices_DWT['A1'] = A1
46 self._matrices_DWT['H1'] = H1
47 self._matrices_DWT['V1'] = V1
48 self._matrices_DWT['D1'] = D1
50 A2,(H2,V2,D2),(_,_,_) = pywt.wavedec2\
55 self._matrices_DWT['A2'] = A2
56 self._matrices_DWT['H2'] = H2
57 self._matrices_DWT['V2'] = V2
58 self._matrices_DWT['D2'] = D2
60 A3,(H3,V3,D3), (_,_,_), (_,_,_) = pywt.wavedec2\
65 self._matrices_DWT['A3'] = A3
66 self._matrices_DWT['H3'] = H3
67 self._matrices_DWT['V3'] = V3
68 self._matrices_DWT['D3'] = D3
72 def get_matrice_DWT(self, matrice):
73 assert matrice in self._matrices_DWT.keys()
74 return self._matrices_DWT[matrice]
77 def set_matrice_DWT(self, matrice, valeur):
78 assert matrice in self._matrices_DWT.keys()
79 self._matrices_DWT[matrice] = valeur
80 self._reconstruit_image(matrice)
83 def _reconstruit_image(self, matrice_modifiee):
84 if '1' in matrice_modifiee:
85 self._hote_marque.putdata(pywt.waverec2((\
86 self._matrices_DWT['A1'],
87 (self._matrices_DWT['H1'],
88 self._matrices_DWT['V1'],
89 self._matrices_DWT['D1'])),
90 self._famille).flatten())
91 elif '2' in matrice_modifiee:
92 print pywt.waverec2((\
93 self._matrices_DWT['A2'],
94 (self._matrices_DWT['H2'],
95 self._matrices_DWT['V2'],
96 self._matrices_DWT['D2']),
97 (self._matrices_DWT['H1'],
98 self._matrices_DWT['V1'],
99 self._matrices_DWT['D1'])),
100 self._famille).flatten()
101 self._hote_marque.putdata(pywt.waverec2((\
102 self._matrices_DWT['A2'],
103 (self._matrices_DWT['H2'],
104 self._matrices_DWT['V2'],
105 self._matrices_DWT['D2']),
106 (self._matrices_DWT['H1'],
107 self._matrices_DWT['V1'],
108 self._matrices_DWT['D1'])),
109 self._famille).flatten())
110 elif '3' in matrice_modifiee:
111 self._hote_marque.putdata(pywt.waverec2((\
112 self._matrices_DWT['A3'],
113 (self._matrices_DWT['H3'],
114 self._matrices_DWT['V3'],
115 self._matrices_DWT['D3']),
116 (self._matrices_DWT['H2'],
117 self._matrices_DWT['V2'],
118 self._matrices_DWT['D2']),
119 (self._matrices_DWT['H1'],
120 self._matrices_DWT['V1'],
121 self._matrices_DWT['D1'])),
122 self._famille).flatten())
125 def get_hote_marque(self):
126 return self._hote_marque
129 if __name__ == '__main__':
130 print "Mise à zéro des matrices d'approximation"
131 for k in ['A1','A2','A3']:
133 unMarquage = Marquage_DWT(hote = 'lena.png',
135 matrice_nulle = zeros(unMarquage.get_matrice_DWT(k).shape)
136 unMarquage.set_matrice_DWT(k,matrice_nulle)
137 unMarquage.get_hote_marque().show()
138 raw_input(' (Appuyez sur une touche)')
141 print "Mise à zéro des matrices de détail D"
142 for k in ['D1','D2','D3']:
144 unMarquage = Marquage_DWT(hote = 'lena.png',
146 matrice_nulle = zeros(unMarquage.get_matrice_DWT(k).shape)
147 unMarquage.set_matrice_DWT(k,matrice_nulle)
148 unMarquage.get_hote_marque().show()
149 raw_input(' (Appuyez sur une touche)')