Skip to content

Commit 133cc02

Browse files
authored
Merge pull request #243 from OpenPIV/static_masking
added static masking option
2 parents 404f770 + bbd4148 commit 133cc02

File tree

3 files changed

+194
-201
lines changed

3 files changed

+194
-201
lines changed

openpiv/test/test_windef.ipynb

Lines changed: 163 additions & 198 deletions
Large diffs are not rendered by default.

openpiv/tools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
from imageio.v3 import imread as _imread, imwrite as _imsave
3333
from skimage.feature import canny
3434

35+
import re
36+
37+
def natural_sort(l):
38+
convert = lambda text: int(text) if text.isdigit() else text.lower()
39+
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
40+
return sorted(l, key=alphanum_key)
3541

3642
def unique(array):
3743
uniq, index = np.unique(array, return_index=True)
@@ -454,7 +460,7 @@ def __init__(self, data_dir, pattern_a, pattern_b=None):
454460
"""
455461
# load lists of images
456462

457-
self.files_a = sorted(
463+
self.files_a = natural_sort(
458464
glob.glob(os.path.join(os.path.abspath(data_dir), pattern_a))
459465
)
460466

openpiv/windef.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ def func(args):
7272
ax.imshow(frame_b, cmap=plt.get_cmap('Blues'), alpha=.5)
7373
plt.show()
7474

75+
if settings.static_masking:
76+
frame_a[settings.static_mask] = 0
77+
frame_b[settings.static_mask] = 0
78+
79+
if settings.show_all_plots:
80+
fig, ax = plt.subplots(1,2)
81+
ax[0].imshow(frame_a)
82+
ax[1].imshow(frame_b)
83+
84+
7585
if settings.dynamic_masking_method in ("edge", "intensity"):
7686
frame_a, mask_a = preprocess.dynamic_masking(
7787
frame_a,
@@ -85,6 +95,16 @@ def func(args):
8595
filter_size=settings.dynamic_masking_filter_size,
8696
threshold=settings.dynamic_masking_threshold,
8797
)
98+
if settings.show_all_plots:
99+
fig, ax = plt.subplots(2,2)
100+
ax[0,0].imshow(frame_a)
101+
ax[0,1].imshow(mask_a)
102+
ax[1,0].imshow(frame_b)
103+
ax[1,1].imshow(mask_b)
104+
# plt.gca().invert_yaxis()
105+
# plt.gca().set_aspect(1.)
106+
# plt.title('after first pass, invert')
107+
# plt.show()
88108

89109
# "first pass"
90110
x, y, u, v, s2n = first_pass(
@@ -741,8 +761,7 @@ def multipass_img_deform(
741761

742762
if settings.show_all_plots:
743763
plt.figure()
744-
nans = np.nonzero(mask)
745-
764+
nans = np.nonzero(mask)[0]
746765
plt.quiver(x[~nans], y[~nans], u[~nans], -v[~nans], color='b')
747766
plt.quiver(x[nans], y[nans], u[nans], -v[nans], color='r')
748767
plt.gca().invert_yaxis()
@@ -922,6 +941,9 @@ def __init__(self):
922941
self.show_all_plots = False
923942

924943
self.invert = False # for the test_invert
944+
945+
self.static_masking = False
946+
self.static_mask = None
925947

926948
self._freeze()
927949

0 commit comments

Comments
 (0)