-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathtutorial2.py
More file actions
39 lines (27 loc) · 1.38 KB
/
tutorial2.py
File metadata and controls
39 lines (27 loc) · 1.38 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
""" Tutorial of using window deformation multi-pass """
from importlib.resources import files
from openpiv import tools, pyprocess, validation, filters
def func( args ):
"""A function to process each image pair."""
# this line is REQUIRED for multiprocessing to work
# always use it in your custom function
file_a, file_b, counter = args
# read images into numpy arrays
frame_a = tools.imread( path / file_a )
frame_b = tools.imread( path / file_b )
# process image pair with extended search area piv algorithm.
u, v, sig2noise = pyprocess.extended_search_area_piv( frame_a, frame_b, \
window_size=64, overlap=32, dt=0.02, search_area_size=128, sig2noise_method='peak2peak')
flags = validation.sig2noise_val( sig2noise, threshold = 1.5 )
u, v = filters.replace_outliers( u, v, flags, method='localmean', max_iter=10, kernel_size=2)
# get window centers coordinates
x, y = pyprocess.get_coordinates( image_size=frame_a.shape, search_area_size=128, overlap=32 )
# save to a file
tools.save(str(path / f'test2_{counter:03d}.txt') , x, y, u, v, flags)
tools.display_vector_field( str(path / f'test2_{counter:03d}.txt') )
path = files('openpiv') / "data" / "test2"
task = tools.Multiprocesser(
data_dir = path, # type: ignore
pattern_a='2image_*0.tif',
pattern_b='2image_*1.tif')
task.run( func = func, n_cpus=2 )