-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathewt_testing.py
More file actions
358 lines (318 loc) · 14.9 KB
/
ewt_testing.py
File metadata and controls
358 lines (318 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import unittest
from ewt import ewt2d
from ewt import boundaries
from ewt import ewt1d
import ewt
import numpy as np
class EWTBlackboxTest(unittest.TestCase):
def setUp(self):
self.f = np.genfromtxt('Tests/2d/texture.csv', delimiter=',')
self.f = (self.f - np.min(self.f)) / (np.max(self.f) - np.min(self.f))
self.params = ewt.utilities.ewt_params()
def test_ewt1dEven(self):
f = np.genfromtxt('Tests/1d/sig2.csv', delimiter=',')
[ewtc, mfb, bounds] = ewt1d.ewt1d(f, self.params)
recon = ewt1d.iewt1d(ewtc,mfb)
self.assertTrue(np.sum((recon - f) ** 2) < 10 ** (-10))
def test_ewt1dOdd(self):
f = np.genfromtxt('Tests/1d/sig2.csv', delimiter=',')
f = f[0:-1]
[ewtc, mfb, bounds] = ewt1d.ewt1d(f, self.params)
recon = ewt1d.iewt1d(ewtc, mfb)
self.assertTrue(np.sum((recon - f) ** 2) < 10 ** (-10))
def testewt2dCurvelet1Even(self):
#Tests empirical curvelet transform + reconstruction for even images
[ewtc, mfb, b1, b2] = ewt2d.ewt2dCurvelet(self.f, self.params)
recon = ewt2d.iewt2dCurvelet(ewtc, mfb)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dCurvelet1Odd(self):
#Tests empirical curvelet transform + reconstruction for odd images
self.f = self.f[0:-1, 0:-1]
[ewtc, mfb, b1, b2] = ewt2d.ewt2dCurvelet(self.f, self.params)
recon = ewt2d.iewt2dCurvelet(ewtc, mfb)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dCurvelet2Even(self):
#Tests empirical curvelet transform + reconstruction for even images
self.params.option = 2
[ewtc, mfb, b1, b2] = ewt2d.ewt2dCurvelet(self.f, self.params)
recon = ewt2d.iewt2dCurvelet(ewtc, mfb)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dCurvelet2Odd(self):
#Tests empirical curvelet transform + reconstruction for odd images
self.f = self.f[0:-1, 0:-1]
self.params.option = 2
[ewtc,mfb,b1,b2] = ewt2d.ewt2dCurvelet(self.f, self.params)
recon = ewt2d.iewt2dCurvelet(ewtc, mfb)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dCurvelet3Even(self):
#Tests empirical curvelet transform + reconstruction for even images
self.params.option = 3
[ewtc, mfb, b1, b2] = ewt2d.ewt2dCurvelet(self.f, self.params)
recon = ewt2d.iewt2dCurvelet(ewtc, mfb)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dCurvelet3Odd(self):
#Tests empirical curvelet transform + reconstruction for odd images
self.f = self.f[0:-1, 0:-1]
self.params.option = 3
[ewtc, mfb, b1, b2] = ewt2d.ewt2dCurvelet(self.f, self.params)
recon = ewt2d.iewt2dCurvelet(ewtc, mfb)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dTensorEven(self):
#Tests empirical tensor transform + reconstruction for odd images
[ewtc, mfb1, mfb2, b1, b2] = ewt2d.ewt2dTensor(self.f, self.params)
recon = ewt2d.iewt2dTensor(ewtc, mfb1, mfb2)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dTensorOdd(self):
#Tests empirical tensor transform + reconstruction for odd images
self.f = self.f[0:-1, 0:-1]
[ewtc, mfb1, mfb2, b1, b2] = ewt2d.ewt2dTensor(self.f, self.params)
recon = ewt2d.iewt2dTensor(ewtc, mfb1, mfb2)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dLPEven(self):
#Tests empirical LP transform + reconstruction for odd images
[ewtc, mfb, bounds] = ewt2d.ewt2dLP(self.f, self.params)
recon = ewt2d.iewt2dLP(ewtc, mfb)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dLPOdd(self):
#Tests empirical LP transform + reconstruction for odd images
self.f = self.f[0:-1, 0:-1]
[ewtc, mfb, bounds] = ewt2d.ewt2dLP(self.f, self.params)
recon = ewt2d.iewt2dLP(ewtc, mfb)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
def testewt2dRidgeletEven(self):
#Tests empirical ridgelet transform + reconstruction for odd images
[ewtc, mfb, bounds] = ewt2d.ewt2dRidgelet(self.f, self.params)
recon = ewt2d.iewt2dRidgelet(ewtc, mfb)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-3))
def testewt2dRidgeletOdd(self):
#Tests empirical ridgelet transform + reconstruction for odd images
self.f = self.f[0:-1, 0:-1]
[ewtc, mfb, bounds] = ewt2d.ewt2dRidgelet(self.f, self.params)
recon = ewt2d.iewt2dRidgelet(ewtc, mfb, 1)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-3))
def testppfft(self):
#Tests pseudo-polar fourier transform
ppff = ewt2d.ppfft(self.f)
recon = ewt2d.ippfft(ppff)
self.assertTrue(np.sum((recon - self.f) ** 2) < 10 ** (-10))
class EWT_UnitTest_Filters(unittest.TestCase):
def test_ewt2d_curveletWavelet1(self):
#Tests curvelet filterbank construction in typical example
h = 127
w = 127
option = 1
bounds_scales = [.5, .9, 1.3, 3] #between 0 and pi
bounds_angles = [-2, -.5, .3] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_curveletWavelet2(self):
#Tests curvelet filterbank construction if given single angular bound
h = 127
w = 127
option = 1
bounds_scales = [.5, .9, 1.3, 3] #between 0 and pi
bounds_angles = [.3] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_curveletWavelet3(self):
#Tests curvelet filterbank construction if given two scales that are very close
h = 127
w = 127
option = 1
epsilon = 0.0000000001
bounds_scales = [.5, .9, 1.3, 1.3 + epsilon, 3] #between 0 and pi
bounds_angles = [-2, -.5, .3] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_curveletWavelet4(self):
#Tests curvelet filterbank construction if given two angles that are very close
h = 127
w = 127
option = 1
bounds_scales = [.5, .9, 1.3, 3] #between 0 and pi
epsilon = 0.0000000001
bounds_angles = [-2, -.5 + epsilon, .3] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_curveletWavelet5(self):
#Tests curvelet filterbank construction if given no scales
h = 127
w = 127
option = 1
bounds_scales = [] #between 0 and pi
bounds_angles = [-2, -.5, .3] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_curveletWavelet6(self):
#Tests curvelet filterbank construction if given no angles
h = 127
w = 127
option = 1
bounds_scales = [.5, .9, 1.3, 3] #between 0 and pi
bounds_angles = [] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_curveletWavelet7(self):
#Tests curvelet filterbank construction if given scale out of bounds (below)
h = 127
w = 127
option = 1
bounds_scales = [-.5, .9, 1.3, 3] #between 0 and pi
bounds_angles = [-2, -.5, .3] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_curveletWavelet8(self):
#Tests curvelet filterbank construction if given scale out of bounds (above)
h = 127
w = 127
option = 1
bounds_scales = [.5, .9, 1.3, 3.4] #between 0 and pi
bounds_angles = [-2, -.5, .3] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_curveletWavelet9(self):
#Tests curvelet filterbank construction if given angle out of bounds (below)
h = 127
w = 127
option = 1
bounds_scales = [.5, .9, 1.3, 3] #between 0 and pi
bounds_angles = [-3, -2, -.5, .3] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_curveletWavelet10(self):
#Tests curvelet filterbank construction if given angle out of bounds (above)
h = 127
w = 127
option = 1
bounds_scales = [.5, .9, 1.3, 3] #between 0 and pi
bounds_angles = [-2, -.5, .3, 1.0] #between -3pi/4(-2.356+ and pi/4 (.7854)
mfb = ewt2d.ewt2d_curveletFilterbank(bounds_scales, bounds_angles, h, w, option)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_LPWavelet1(self):
#Tests LP filterbank construction in normal circumstances
h = 127
w = 127
bounds_scales = [.5, .9, 1.3, 3] #between 0 and pi
mfb = ewt2d.ewt2d_LPFilterbank(bounds_scales, h, w)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
def test_ewt2d_LPWavelet2(self):
#Tests LP filterbank construction if no scales detected
h = 127
w = 127
bounds_scales = [] #between 0 and pi
mfb = ewt2d.ewt2d_LPFilterbank(bounds_scales, h, w)
tmp = np.zeros([h, w])
for i in range(0, len(mfb)):
for j in range(0, len(mfb[i])):
tmp += mfb[i][j] ** 2
self.assertAlmostEqual(np.max(tmp), 1.0)
self.assertAlmostEqual(np.min(tmp), 1.0)
class EWT_UnitTest_Boundaries(unittest.TestCase):
def test_boundaries_localmin1(self):
#basic test for localmin
inp = np.array([1, 0, 1])
out = np.array([0, 1, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
def test_boundaries_localmin2(self):
#boundary test for localmin
inp = np.array([0, 1, 2, 0, 1, 0])
out = np.array([0, 0, 0, 1, 0, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
def test_boundaries_localmin3(self):
#even plateau test for localmin
inp = np.array([2, 1, 0, 0, 1, 2])
out = np.array([0 ,0, 1, 0, 0, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
def test_boundaries_localmin4(self):
#odd plateau test for localmin
inp = np.array([2, 1, 0, 0, 0, 1, 2])
out = np.array([0 ,0, 0, 1, 0, 0, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
def test_boundaries_localmin5(self):
#boundary even plateau test for localmin
inp = np.array([0, 0, 1, 2, 0, 0])
out = np.array([0, 1, 0, 0, 1, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
def test_boundaries_localmin6(self):
#boundary odd plateau test for localmin
inp = np.array([0, 0, 0, 1, 2, 0, 0, 0])
out = np.array([0 ,1, 0, 0, 0, 0, 1, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
def test_boundaries_localmin7(self):
#saddle test for localmin
inp = np.array([3, 2, 2, 2, 1, 0, 2])
out = np.array([0 ,0, 0, 0, 0, 1, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
def test_boundaries_localmin8(self):
#odd flat test for localmin
inp = np.array([0, 0, 0])
out = np.array([0, 1, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
def test_boundaries_localmin9(self):
#even flat test for localmin
inp = np.array([0, 0, 0, 0])
out = np.array([0 ,1, 0, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
def test_boundaries_localmin10(self):
#epsilon test for localmin
epsilon = .00000000000000001
inp = np.array([2, 1, 0 - epsilon, 0 + epsilon, 0 - epsilon, 1, 2])
out = np.array([0 ,0, 1, 0, 1, 0, 0], 'bool')
self.assertTrue(np.all(boundaries.localmin(inp) == out))
if __name__ == '__main__':
unittest.main()