/
test_windef.py
172 lines (154 loc) · 4.67 KB
/
test_windef.py
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
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 4 14:33:21 2019
@author: Theo
"""
import numpy as np
import openpiv.windef as windef
from test_process import create_pair, shift_u, shift_v, threshold
frame_a, frame_b = create_pair(image_size=256)
# this test are created only to test the displacement evaluation of the
# function the validation methods are not tested here ant therefore
# are disabled.
# circular cross correlation
def test_first_pass_circ():
""" test of the first pass """
x, y, u, v, s2n = windef.first_pass(
frame_a,
frame_b,
window_size=64,
overlap=32,
iterations=1,
correlation_method="circular",
subpixel_method="gaussian",
do_sig2noise=True,
sig2noise_method="peak2peak",
sig2noise_mask=2,
)
print("\n", x, y, u, v, s2n)
assert np.mean(np.abs(u - shift_u)) < threshold
assert np.mean(np.abs(v - shift_v)) < threshold
def test_multi_pass_circ():
""" test fot the multipass """
window_size = (128, 64, 32)
overlap = (64, 32, 16)
iterations = 3
x, y, u, v, s2n = windef.first_pass(
frame_a,
frame_b,
window_size[0],
overlap[0],
iterations,
correlation_method="circular",
subpixel_method="gaussian",
do_sig2noise=True,
sig2noise_method="peak2peak",
sig2noise_mask=2,
)
u_old = u.copy()
v_old = v.copy()
i = 1
for i in range(2, iterations + 1):
x, y, u, v, s2n, mask = windef.multipass_img_deform(
frame_a,
frame_b,
window_size[i - 1],
overlap[i - 1],
iterations,
i,
x,
y,
u,
v,
correlation_method="circular",
subpixel_method="gaussian",
deformation_method="symmetric",
do_sig2noise=False,
sig2noise_method="peak2peak",
sig2noise_mask=2,
MinMaxU=(-100, 50),
MinMaxV=(-50, 50),
std_threshold=1000000,
median_threshold=200000,
median_size=1,
filter_method="localmean",
max_filter_iteration=10,
filter_kernel_size=2,
interpolation_order=3,
)
print("\n", x, y, u, v, s2n)
assert np.mean(np.abs(u - shift_u)) < threshold and np.any(u != u_old)
assert np.mean(np.abs(v - shift_v)) < threshold and np.any(v != v_old)
# the second condition is to check if the multipass is done.
# It need's a little numerical inaccuracy.
# linear cross correlation
def test_first_pass_lin():
""" test of the first pass """
x, y, u, v, s2n = windef.first_pass(
frame_a,
frame_b,
window_size=64,
overlap=32,
iterations=1,
correlation_method="linear",
subpixel_method="gaussian",
do_sig2noise=True,
sig2noise_method="peak2peak",
sig2noise_mask=2,
)
print("\n", x, y, u, v, s2n)
assert np.mean(np.abs(u - shift_u)) < threshold
assert np.mean(np.abs(v - shift_v)) < threshold
def test_multi_pass_lin():
""" test fot the multipass """
window_size = (128, 64, 32)
overlap = (64, 32, 16)
iterations = 3
x, y, u, v, s2n = windef.first_pass(
frame_a,
frame_b,
window_size[0],
overlap[0],
iterations,
correlation_method="linear",
subpixel_method="gaussian",
do_sig2noise=True,
sig2noise_method="peak2peak",
sig2noise_mask=2,
)
u_old = u.copy()
v_old = v.copy()
i = 1
for i in range(2, iterations + 1):
x, y, u, v, sn, m = windef.multipass_img_deform(
frame_a,
frame_b,
window_size[i - 1],
overlap[i - 1],
iterations,
i,
x,
y,
u,
v,
correlation_method="linear",
subpixel_method="gaussian",
deformation_method="symmetric",
do_sig2noise=False,
sig2noise_method="peak2peak",
sig2noise_mask=2,
MinMaxU=(-100, 50),
MinMaxV=(-50, 50),
std_threshold=1000000,
median_threshold=200000,
median_size=1,
filter_method="localmean",
max_filter_iteration=10,
filter_kernel_size=2,
interpolation_order=3,
)
print("\n", x, y, u, v, s2n)
assert np.mean(np.abs(u - shift_u)) < threshold and np.any(u != u_old)
assert np.mean(np.abs(v - shift_v)) < threshold and np.any(v != v_old)
# the second condition is to check if the multipass is done.
# It need's a little numerical inaccuracy.