%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.11%22%0A%23%20dependencies%20%3D%20%5B%0A%23%20%20%20%20%20%22marimo%22%2C%0A%23%20%20%20%20%20%22openpiv%3D%3D0.26.3%22%2C%0A%23%20%20%20%20%20%22numpy%22%2C%0A%23%20%20%20%20%20%22matplotlib%22%2C%0A%23%20%20%20%20%20%22scipy%22%2C%0A%23%20%20%20%20%20%22scikit-image%22%2C%0A%23%20%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%2005%20%E2%80%94%20Masking%20%26%20preprocessing%0A%0A%20%20%20%20Real%20experiments%20often%20include%20walls%2C%20models%2C%20bubbles%2C%20or%20moving%20objects%20that%20should%20not%20be%20treated%20as%20flow.%20**Masking**%20excludes%20them.%0A%0A%20%20%20%20%23%23%20Types%0A%20%20%20%20-%20**Static%20mask**%3A%20known%20geometry%20constant%20across%20frames.%0A%20%20%20%20-%20**Dynamic%20mask**%3A%20objects%20detected%20per%20image%2Fframe.%0A%0A%20%20%20%20%23%23%20Learn%20from%20these%20examples%0A%20%20%20%20-%20**%5Bdynamic_masking%5D(marimo_notebooks%2Fdynamic_masking.html)**%20(%5Binteractive%20.py%5D(marimo_notebooks%2Fdynamic_masking.py)%2C%20%5Bmolab%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2Fopenpiv%2Fopenpiv-python-examples%2Fblob%2Fmain%2Fmarimo_notebooks%2Fdynamic_masking.py))%20%E2%80%94%20remove%20moving%20objects%20dynamically.%20*Use%20when%3A*%20objects%20move%20through%20the%20field%20of%20view.%0A%20%20%20%20-%20**%5Bopenpiv_static_masking_example%5D(marimo_notebooks%2Fopenpiv_static_masking_example.html)**%20(%5Binteractive%20.py%5D(marimo_notebooks%2Fopenpiv_static_masking_example.py)%2C%20%5Bmolab%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2Fopenpiv%2Fopenpiv-python-examples%2Fblob%2Fmain%2Fmarimo_notebooks%2Fopenpiv_static_masking_example.py))%20%E2%80%94%20apply%20a%20static%20mask%20(e.g.%20circular%20region)%20in%20multi-pass%20windef.%20*Use%20when%3A*%20geometry%20is%20fixed.%0A%20%20%20%20-%20**%5Bpreprocessing_filters%5D(marimo_notebooks%2Fpreprocessing_filters.html)**%20(%5Binteractive%20.py%5D(marimo_notebooks%2Fpreprocessing_filters.py)%2C%20%5Bmolab%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2Fopenpiv%2Fopenpiv-python-examples%2Fblob%2Fmain%2Fmarimo_notebooks%2Fpreprocessing_filters.py))%20%E2%80%94%20spatial%2Ftemporal%20filters%20for%20image%20enhancement%20and%20background%20subtraction.%0A%20%20%20%20-%20**%5Btest21%20case%5D(marimo_cases%2Ftest21.html)**%20(%5Binteractive%20.py%5D(marimo_cases%2Ftest21.py))%20%E2%80%94%20bubbles%20with%20a%20provided%20mask%20image%20(%60bubblesMask.png%60).%0A%20%20%20%20-%20**%5Bphase_separation%5D(marimo_notebooks%2Fphase_separation.html)**%20(%5Binteractive%20.py%5D(marimo_notebooks%2Fphase_separation.py)%2C%20%5Bmolab%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2Fopenpiv%2Fopenpiv-python-examples%2Fblob%2Fmain%2Fmarimo_notebooks%2Fphase_separation.py))%20%E2%80%94%20separate%20phases%20in%20two-phase%20PIV%20before%20analysis.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20openpiv.tools%20import%20synimage%0A%20%20%20%20from%20openpiv%20import%20preprocess%0A%20%20%20%20img_a%2C%20_%20%3D%20synimage.synimagegen(128)%0A%20%20%20%20masked%2C%20mask%20%3D%20preprocess.dynamic_masking(img_a%2C%20method%3D'edges')%0A%20%20%20%20print('masked%20shape%3A'%2C%20masked.shape%2C%20'masked%20pixels%3A'%2C%20int((mask%20%3E%200).sum()))%0A%20%20%20%20return%20img_a%2C%20mask%2C%20masked%0A%0A%0A%40app.cell%0Adef%20_(img_a%2C%20mask%2C%20masked)%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt1%0A%20%20%20%20fig1%2C%20ax1%20%3D%20plt1.subplots(1%2C%203%2C%20figsize%3D(10%2C%203))%0A%20%20%20%20ax1%5B0%5D.imshow(img_a%2C%20cmap%3D'gray')%3B%20ax1%5B0%5D.set_title('Original')%0A%20%20%20%20ax1%5B1%5D.imshow(mask%2C%20cmap%3D'gray')%3B%20ax1%5B1%5D.set_title('Mask')%0A%20%20%20%20ax1%5B2%5D.imshow(masked%2C%20cmap%3D'gray')%3B%20ax1%5B2%5D.set_title('Masked%20image')%0A%20%20%20%20fig1%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Tips%0A%20%20%20%20-%20Inspect%20masks%20visually%20%E2%80%94%20over-masking%20removes%20valid%20flow%2C%20under-masking%20creates%20spurious%20vectors.%0A%20%20%20%20-%20Combine%20preprocessing%20carefully%3B%20aggressive%20filtering%20can%20distort%20particle%20images.%0A%20%20%20%20-%20For%20moving%20boundaries%2C%20dynamic%20masking%20per%20frame%20(or%20pair)%20is%20often%20necessary.%0A%0A%20%20%20%20Next%3A%20%5B06%20%E2%80%94%20Tips%2C%20tricks%20%26%20pitfalls%5D(06_tips_tricks_pitfalls.html)%0A%20%20%20%20%22%22%22)%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
8609dfc3db75f522856bf765463058f8