See the post on LinkedIn by Stefano Brizzolara https://www.linkedin.com/posts/stefano-brizzolara-6a8501198_rheinfall-flowvisualization-ugcPost-6672832128742408192-lRub
from openpiv import tools, pyprocess, validation, filters, scaling
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import imageio
frame_a = tools.imread('../test8/frame0001.tif')
frame_b = tools.imread('../test8/frame0002.tif')
fig,ax = plt.subplots(1,2,figsize=(12,10))
ax[0].imshow(frame_a,cmap=plt.cm.gray)
ax[1].imshow(frame_b,cmap=plt.cm.gray)
<matplotlib.image.AxesImage at 0x7f411fdfd6d0>
# %pdb
# np.seterr(all="raise")
winsize = 24 # pixels
searchsize = 48 # pixels, search in image B
overlap = 12 # pixels
dt = 1./30 # sec, assume 30 fps
frame_a[:600,:] = 0 # basically masking out the non-illuminated region
frame_b[:600,:] = 0
u0, v0, sig2noise = pyprocess.extended_search_area_piv(frame_a.astype(np.int32),
frame_b.astype(np.int32),
window_size=winsize,
overlap=overlap, dt=dt,
search_area_size=searchsize,
sig2noise_method='peak2peak',
correlation_method='linear',
normalized_correlation=True)
x, y = pyprocess.get_coordinates(frame_a.shape,searchsize, overlap)
mask = validation.sig2noise_val(sig2noise, threshold = 1.2)
u2, v2 = filters.replace_outliers( u0, v0, mask, method='localmean', max_iter=1, kernel_size=3)
# x, y, u3, v3 = scaling.uniform(x, y, u2, v2, scaling_factor = 1. )
x, y, u2, v2 = tools.transform_coordinates(x, y, u2, v2)
tools.save('exp1_001.txt', x, y, u2, v2, mask )
# tools.display_vector_field('exp1_001.txt', scaling_factor=100., width=0.0025)
# If you need a larger view:
fig, ax = plt.subplots(figsize=(12,12))
tools.display_vector_field('exp1_001.txt', ax=ax, scaling_factor=1.0,
scale=1000, width=0.0045, on_img=True,
image_name='../test8/frame0001.tif');
from openpiv.windef import PIVSettings, Multiprocesser, piv
settings = PIVSettings()
settings.filepath_images = '../test8'
settings.frame_pattern_a = 'frame00*.tif'
settings.frame_pattern_b = '(1+2),(2+3)'
settings.show_plot=True
piv(settings)
../test8 frame00*.tif True [PosixPath('../test8/frame0001.tif'), PosixPath('../test8/frame0002.tif'), PosixPath('../test8/frame0003.tif'), PosixPath('../test8/frame0004.tif'), PosixPath('../test8/frame0005.tif'), PosixPath('../test8/frame0006.tif'), PosixPath('../test8/frame0007.tif'), PosixPath('../test8/frame0008.tif'), PosixPath('../test8/frame0009.tif'), PosixPath('../test8/frame0010.tif')]
Image Pair 1 frame0001 frame0002
Image Pair 2 frame0002 frame0003
Image Pair 3 frame0003 frame0004
Image Pair 4 frame0004 frame0005
Image Pair 5 frame0005 frame0006
Image Pair 6 frame0006 frame0007
Image Pair 7 frame0007 frame0008
Image Pair 8 frame0008 frame0009
Image Pair 9 frame0009 frame0010