import%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20OpenPIV%20static%20masking%20example%25load_ext%20watermark%0A%20%20%20%20%23%20magic%20command%20not%20supported%20in%20marimo%3B%20please%20file%20an%20issue%20to%20add%20support%0A%20%20%20%20%23%20%25watermark%20-v%20-m%20-p%20numpy%2Copenpiv%20-g%20-b%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20magic%20command%20not%20supported%20in%20marimo%3B%20please%20file%20an%20issue%20to%20add%20support%0A%20%20%20%20%23%20%25load_ext%20watermark%0A%20%20%20%20%23%20magic%20command%20not%20supported%20in%20marimo%3B%20please%20file%20an%20issue%20to%20add%20support%0A%20%20%20%20%23%20%25watermark%20-v%20-m%20-p%20numpy%2Copenpiv%20-g%20-b%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20from%20openpiv%20import%20tools%0A%20%20%20%20from%20openpiv.piv%20import%20simple_piv%0A%0A%20%20%20%20import%20pathlib%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20numpy%20as%20np%0A%0A%20%20%20%20return%20np%2C%20pathlib%2C%20plt%2C%20simple_piv%2C%20tools%0A%0A%0A%40app.cell%0Adef%20_(pathlib)%3A%0A%20%20%20%20images%20%3D%20sorted(pathlib.Path('..%2Ftest9').glob('*.jpg'))%0A%20%20%20%20print(images)%0A%20%20%20%20return%20(images%2C)%0A%0A%0A%40app.cell%0Adef%20_(images%2C%20np%2C%20plt%2C%20tools)%3A%0A%20%20%20%20a%2Cb%20%3D%20tools.imread(images%5B0%5D)%2C%20tools.imread(images%5B1%5D)%0A%20%20%20%20plt.imshow(np.c_%5Ba%2Cb%5D)%0A%20%20%20%20return%20a%2C%20b%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20We%20see%20the%20mask%20as%20a%20circle%2C%20but%20OpenPIV%20does%20not%20know%20about%20it%2C%20we%20see%20some%20vectors%20%22inside%20the%20masked%20region%22.%20Since%20the%20arrows%20inside%20are%20erroneous%2C%20these%20are%20removed%20in%20the%20post-processing%20validation.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(a%2C%20b%2C%20simple_piv)%3A%0A%20%20%20%20simple_piv(a%2Cb)%3B%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Let's%20create%20a%20mask%20-%20it's%20an%20image%20size%20matrix%20of%20booleans%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(a%2C%20np%2C%20plt)%3A%0A%20%20%20%20from%20skimage.morphology%20import%20binary_dilation%2C%20disk%2C%20white_tophat%0A%0A%0A%20%20%20%20%23%20binary%20thresholding%20-%20all%20above%20210%20can%20be%20an%20object%0A%20%20%20%20mask%20%3D%20a%20%3E%20210%0A%0A%20%20%20%20%23%20remove%20tracers%3A%0A%20%20%20%20mask%20%3D%20np.logical_xor(mask%2C%20white_tophat(mask%2C%20disk(3)))%20%23%20remove%20small%20objects%0A%0A%20%20%20%20%23%20increase%20a%20bit%20the%20mask%20borders%20%0A%20%20%20%20mask%20%3D%20binary_dilation(mask%2C%20disk(7))%20%23%20dilate%20large%20object%0A%0A%20%20%20%20plt.imshow(mask)%0A%20%20%20%20return%20(mask%2C)%0A%0A%0A%40app.cell%0Adef%20_(a%2C%20b%2C%20mask%2C%20np%2C%20plt)%3A%0A%20%20%20%20%23%20long%20and%20descriptive%20way%3A%0A%20%20%20%20masked_a%20%3D%20a.copy()%0A%20%20%20%20masked_b%20%3D%20b.copy()%0A%20%20%20%20masked_a%5Bmask%5D%20%3D%200%0A%20%20%20%20masked_b%5Bmask%5D%20%3D%200%0A%20%20%20%20plt.imshow(np.c_%5Bmasked_a%2C%20masked_b%5D)%0A%20%20%20%20return%20masked_a%2C%20masked_b%0A%0A%0A%40app.cell%0Adef%20_(masked_a%2C%20masked_b%2C%20simple_piv)%3A%0A%20%20%20%20simple_piv(masked_a%2C%20masked_b)%3B%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(a%2C%20b%2C%20mask%2C%20simple_piv)%3A%0A%20%20%20%20%23%20shorthand%0A%20%20%20%20masked_a_1%20%3D%20a%20%7C%20mask%0A%20%20%20%20masked_b_1%20%3D%20b%20%7C%20mask%0A%20%20%20%20simple_piv(masked_a_1%2C%20masked_b_1)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20How%20to%20use%20static%20masking%20with%20multi-pass%20window%20deformation%20processor%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(images%2C%20mask%2C%20pathlib)%3A%0A%20%20%20%20from%20openpiv%20import%20windef%0A%20%20%20%20settings%20%3D%20windef.PIVSettings()%0A%20%20%20%20settings.filepath_images%20%3D%20pathlib.Path('.')%0A%20%20%20%20settings.frame_pattern_a%20%3D%20str(images%5B0%5D)%0A%20%20%20%20settings.frame_pattern_b%20%3D%20str(images%5B1%5D)%0A%0A%20%20%20%20settings.static_masking%20%3D%20True%0A%20%20%20%20settings.static_mask%20%3D%20mask%0A%20%20%20%20settings.show_all_plots%20%3D%20True%0A%20%20%20%20settings.show_plot%20%3D%20True%0A%20%20%20%20return%20settings%2C%20windef%0A%0A%0A%40app.cell%0Adef%20_(settings%2C%20windef)%3A%0A%20%20%20%20windef.piv(settings)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
227e2f93ff79d3366aaf1802eaae8ce9