myimagelib.pivLib.apply_mask¶
- myimagelib.pivLib.apply_mask(pivData, mask)¶
Apply a mask on PIV data, by adding a boolean column “mask” to the original x, y, u, v data file. Valid velocities are labeled
True
while invalid velocities are labeledFalse
.- Parameters
pivData (pandas.DataFrame) – PIV data (x, y, u, v)
mask (2D array) – an image, preferrably binary, where large value denotes valid data and small value denote invalid data. The image will be converted to a boolean array by
mask = mask > mask.mean()
.
- Returns
masked PIV data.
- Return type
pandas.DataFrame
Test
pivData = pd.read_csv("test_files/piv-test.csv") mask = io.imread("test_files/mask.tif") mpiv = apply_mask(pivData, mask) fig, ax = plt.subplots(nrows=1, ncols=2) ax[0].imshow(mask, cmap="gray") ax[0].quiver(pivData.x, pivData.y, pivData.u, pivData.v, color="red") ax[1].imshow(mask, cmap="gray") ax[1].quiver(mpiv.x, mpiv.y, mpiv.u, mpiv.v, color="red")
Edit
Nov 17, 2022 – Initial commit.
Nov 30, 2022 – Instead of replacing invalid data with
np.nan
, add an additional column, where the validity of data is specified.Dec 01, 2022 – Remove the erosion step, since it is very obsecure to include this step here. If we want the mask to be more conservative (include less region to be sure that we are free from boundary effect), we can modify the mask in ImageJ and apply again on the PIV data.
Dec 19, 2022 – Modify docstring to be consistent with code action.