# %loadpy tutorial-part1.py
# import sys
# sys.path.append('/Users/alex/Documents/OpenPIV/openpiv-python')
import openpiv.tools
import openpiv.process
import openpiv.scaling
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
frame_a = openpiv.tools.imread( 'exp1_001_a.bmp' )
frame_b = openpiv.tools.imread( 'exp1_001_b.bmp' )
fig,ax = plt.subplots(1,2)
ax[0].imshow(frame_a,cmap=plt.cm.gray)
ax[1].imshow(frame_b,cmap=plt.cm.gray)
<matplotlib.image.AxesImage at 0x11cbf370>
winsize = 24 # pixels
searchsize = 64 # pixels, search in image B
overlap = 12 # pixels
dt = 0.02 # sec
u0, v0, sig2noise = openpiv.process.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' )
x, y = openpiv.process.get_coordinates( image_size=frame_a.shape, window_size=winsize, overlap=overlap )
u1, v1, mask = openpiv.validation.sig2noise_val( u0, v0, sig2noise, threshold = 1.3 )
print np.nansum((u1 - u0)**2)
0.0
u2, v2 = openpiv.filters.replace_outliers( u1, v1, method='localmean', max_iter=10, kernel_size=2)
print np.nansum((u2 - u1)**2)
0.0
x, y, u3, v3 = openpiv.scaling.uniform(x, y, u2, v2, scaling_factor = 96.52 )
print np.nansum((u3 - u2)**2)
836665.088096
openpiv.tools.save(x, y, u3, v3, mask, 'exp1_001.txt' )
openpiv.tools.display_vector_field('exp1_001.txt', scale=100, width=0.0025)