Thanks to the great service of mybinder.org
from openpiv import tools, process, validation, filters, scaling, pyprocess
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from IPython.display import display
from ipywidgets import interact_manual, interactive, fixed, IntSlider, HBox, VBox, Layout
/Users/alex/anaconda3/envs/py27/lib/python2.7/site-packages/dask/array/numpy_compat.py:32: RuntimeWarning: divide by zero encountered in divide not np.allclose(np.divide(1, .5, dtype='i8'), 2) or
frame_a = tools.imread( 'exp1_001_b.bmp' )
frame_b = tools.imread( 'exp1_001_c.bmp' )
fig,ax = plt.subplots(1,2,figsize=(10,8))
ax[0].imshow(frame_a,cmap=plt.cm.gray)
ax[1].imshow(frame_b,cmap=plt.cm.gray)
<matplotlib.image.AxesImage at 0x1c13ca5650>
winsize = 24 # pixels
searchsize = 64 # pixels, search in image B
overlap = 12 # pixels
dt = 0.02 # sec
u, v, sig2noise = 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 = process.get_coordinates( image_size=frame_a.shape, window_size=winsize, overlap=overlap )
u, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 1.3 )
u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2)
x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 )
tools.save(x, y, u, v, mask, 'exp1_001.txt' )
tools.display_vector_field('exp1_001.txt', scale=100, width=0.0025)
For instance we can use images from PIV Challenge http://www.pivchallenge.org/
frame_a = tools.imread('http://www.pivchallenge.org/pub/B/B001_1.tif')
frame_b = tools.imread('http://www.pivchallenge.org/pub/B/B001_2.tif')
fig,ax = plt.subplots(1,2,figsize=(10,8))
ax[0].imshow(frame_a,cmap=plt.cm.gray)
ax[1].imshow(frame_b,cmap=plt.cm.gray)
<matplotlib.image.AxesImage at 0x1c1458c990>
winsize = 32 # pixels
searchsize = 64 # pixels, search in image B
overlap = 16 # pixels
dt = 1.0 # sec
u0, v0, sig2noise = 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 = process.get_coordinates( image_size=frame_a.shape, window_size=winsize, overlap=overlap )
u, v, mask = validation.sig2noise_val( u0, v0, sig2noise, threshold = 1.1 )
u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2)
# x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 )
plt.figure(figsize=(10,8))
plt.quiver(x,y,u,v,color='b')
plt.quiver(x[mask],y[mask],u[mask],v[mask],color='r')
<matplotlib.quiver.Quiver at 0x1c151910d0>
read more about those on https://ipywidgets.readthedocs.io/en/stable/index.html
from ipywidgets import interact, interactive, fixed, interact_manual
def func(winsize,overlap,searchsize,s2n_method,s2n_threshold):
if overlap >= winsize:
overlap -= 1
u, v, sig2noise = 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=s2n_method )
x, y = process.get_coordinates( image_size=frame_a.shape, window_size=winsize, overlap=overlap )
u, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = s2n_threshold )
u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2)
plt.figure(figsize=(10,8))
plt.quiver(x,y,u,v,color='b')
plt.quiver(x[mask],y[mask],u[mask],v[mask],color='r');
def run():
w = interactive(func,winsize=[32,8,16,64,128],
overlap=[16,8,32,64],
searchsize=[64,16,32,128,256],
s2n_method=['peak2peak','peak2mean'],
s2n_threshold=(1,10,.1));
box_layout = Layout(display='flex', flex_flow='row', justify_content='space-between', align_items='flex-start')
par = VBox([_ for _ in w.children[:-1]])
display(HBox([w.children[-1],par], layout=box_layout))
run()
Failed to display Jupyter Widget of type HBox
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
run()
Failed to display Jupyter Widget of type interactive
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
from IPython.display import Image
Image(url='http://www.jpiv.vennemann-online.de/fig/bode.gif')
# read it:
gif = tools.imread('http://www.jpiv.vennemann-online.de/fig/bode.gif')
# convert to gray scale
from skimage import img_as_uint
frame_a = img_as_uint(gif[0])
frame_b = img_as_uint(gif[1])
/Users/alex/anaconda3/envs/py27/lib/python2.7/site-packages/skimage/util/dtype.py:122: UserWarning: Possible precision loss when converting from float64 to uint16 .format(dtypeobj_in, dtypeobj_out))
# see if this is what you want
plt.figure()
plt.imshow(frame_a,cmap=plt.cm.gray)
<matplotlib.image.AxesImage at 0x1c142a6590>
def run():
w = interactive(func,winsize=[64,8,16,64,128],
overlap=[32,8,32,64],
searchsize=[64,16,32,128,256],
s2n_method=['peak2peak','peak2mean'],
s2n_threshold=(1,1.5,.1));
box_layout = Layout(display='flex', flex_flow='row', justify_content='space-between', align_items='flex-start')
par = VBox([_ for _ in w.children[:-1]])
display(HBox([w.children[-1],par], layout=box_layout))
run()
Failed to display Jupyter Widget of type HBox
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.