# %load red_Cell.py
from openpiv import tools, pyprocess, scaling, filters, \
validation
from openpiv import widim
import numpy as np
import matplotlib.pyplot as plt
import imageio
from pylab import *
%matplotlib inline
from skimage import img_as_uint
frame_a = tools.imread('../test3/Y4-S3_Camera000398.tif')
frame_b = tools.imread('../test3/Y4-S3_Camera000399.tif')
plt.imshow(np.c_[frame_a[40:,:-40],frame_b[40:,:-40]],cmap=plt.cm.gray)
<matplotlib.image.AxesImage at 0x7f9c1066da30>
frame_a = frame_a[40:, :-40].astype(np.int32) # change of type for the Cython WiDIM
frame_b = frame_b[40:, :-40].astype(np.int32)
# Use Python version, pyprocess:
u, v, sig2noise = pyprocess.extended_search_area_piv( frame_a, frame_b,
window_size=32,
overlap=16,
search_area_size=32,
dt=.1,
sig2noise_method='peak2peak',
normalized_correlation=True,
correlation_method = 'circular')
x, y = pyprocess.get_coordinates(image_size=frame_a.shape,
search_area_size=32,
overlap=16)
plt.quiver(x,y,u,v,sig2noise)
plt.gca().invert_yaxis()
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7f9c0cd27a60>
plt.hist(sig2noise.flatten());
p = percentile(sig2noise,5) # bottom 5%
plt.plot([p,p],[0,35],lw=2)
[<matplotlib.lines.Line2D at 0x7f9c0ccbceb0>]
u, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = p )
u, v = filters.replace_outliers( u, v, method='localmean', max_iter=1, kernel_size=2)
x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 1. )
tools.save(x, y, u, v, sig2noise, mask, 'Y4-S3_Camera000398_a.txt' )
# "natural" view without image
fig,ax = plt.subplots(2,1,figsize=(6,12))
ax[0].invert_yaxis()
ax[0].quiver(x,y,u,v)
ax[0].set_title(' Sort of natural view ')
ax[1].quiver(x,y,u,v)
ax[1].set_title('Quiver with 0,0 origin needs `negative` v for visualization purposes');
# plt.quiver(x,y,u,v)
fig,ax = plt.subplots(figsize=(8,8))
tools.display_vector_field('Y4-S3_Camera000398_a.txt',
on_img=True,
image_name='../test3/Y4-S3_Camera000398.tif',
scaling_factor=1.,
ax = ax)
(<Figure size 576x576 with 1 Axes>, <AxesSubplot:>)
tools.display_vector_field('Y4-S3_Camera000398_a.txt')
(<Figure size 432x288 with 1 Axes>, <AxesSubplot:>)
x,y,u,v, mask = widim.WiDIM(frame_a.astype(np.int32),
frame_b.astype(np.int32),
ones_like(frame_a).astype(np.int32),
min_window_size=32,
overlap_ratio=0.25,
coarse_factor=0,
dt=0.1,
validation_method='mean_velocity',
trust_1st_iter=0,
validation_iter=0,
tolerance=0.7,
nb_iter_max=1,
sig2noise_method='peak2peak')
---------------------------------------------------------- |-----> || The Open Source P article | | Open || I mage | | PIV || V elocimetry Toolbox | | <-----|| www.openpiv.net version 1.0 | ---------------------------------------------------------- ('Algorithm : ', 'WiDIM') Parameters ----------------------------------- (' ', 'Size of image', ' | ', [244, 216]) (' ', 'total number of iterations', ' | ', 1) (' ', 'overlap ratio', ' | ', 0.25) (' ', 'coarse factor', ' | ', 0) (' ', 'time step', ' | ', 0.10000000149011612) (' ', 'validation method', ' | ', 'None') (' ', 'number of validation iterations', ' | ', 0) (' ', 'subpixel_method', ' | ', 'gaussian') (' ', 'Nrow', ' | ', array([9], dtype=int32)) (' ', 'Ncol', ' | ', array([8], dtype=int32)) (' ', 'Window sizes', ' | ', array([32], dtype=int32)) ----------------------------------- | STARTING | ----------------------------------- ('ITERATION # ', 0) ..[DONE] (' --residual : ', 0.9999999896339749) Starting validation.. ..[DONE] ////////////////////////////////////////////////////////////////// end of iterative process.. Re-arranging vector fields.. ...[DONE] ------------------------------------------------------------- ('[DONE] ..after ', -32.18250584602356, 'seconds ') -------------------------------------------------------------
tools.save(x, y, u, v, 0*v, 0*v, 'Y4-S3_Camera000398_widim1.txt' )
x,y,u,v, mask = widim.WiDIM(frame_a.astype(np.int32),
frame_b.astype(np.int32),
ones_like(frame_a).astype(np.int32),
min_window_size=16,
overlap_ratio=0.25,
coarse_factor=2,
dt=0.1,
validation_method='mean_velocity',
trust_1st_iter=1,
validation_iter=2,
tolerance=0.7,
nb_iter_max=4,
sig2noise_method='peak2peak')
---------------------------------------------------------- |-----> || The Open Source P article | | Open || I mage | | PIV || V elocimetry Toolbox | | <-----|| www.openpiv.net version 1.0 | ---------------------------------------------------------- ('Algorithm : ', 'WiDIM') Parameters ----------------------------------- (' ', 'Size of image', ' | ', [244, 216]) (' ', 'total number of iterations', ' | ', 4) (' ', 'overlap ratio', ' | ', 0.25) (' ', 'coarse factor', ' | ', 2) (' ', 'time step', ' | ', 0.10000000149011612) (' ', 'validation method', ' | ', 'mean_velocity') (' ', 'number of validation iterations', ' | ', 2) (' ', 'subpixel_method', ' | ', 'gaussian') (' ', 'Nrow', ' | ', array([ 4, 9, 20, 20], dtype=int32)) (' ', 'Ncol', ' | ', array([ 4, 8, 17, 17], dtype=int32)) (' ', 'Window sizes', ' | ', array([64, 32, 16, 16], dtype=int32)) ----------------------------------- | STARTING | ----------------------------------- ('ITERATION # ', 0) ..[DONE] (' --residual : ', 1.0) no validation : trusting 1st iteration going to next iteration.. performing interpolation of the displacement field ('..[DONE] -----> going to iteration ', 1) ('ITERATION # ', 1) ..[DONE] (' --residual : ', 0.6296296296296297) Starting validation.. ('Validation, iteration number ', 0) ('Validation, iteration number ', 1) ..[DONE] going to next iteration.. performing interpolation of the displacement field ('..[DONE] -----> going to iteration ', 2) ('ITERATION # ', 2) ..[DONE] (' --residual : ', 0.9098039215686274) Starting validation.. ('Validation, iteration number ', 0) ('Validation, iteration number ', 1) ..[DONE] going to next iteration.. performing interpolation of the displacement field ('..[DONE] -----> going to iteration ', 3) ('ITERATION # ', 3) ..[DONE] (' --residual : ', 1.631372549019608) Starting validation.. ('Validation, iteration number ', 0) ('Validation, iteration number ', 1) ..[DONE] ////////////////////////////////////////////////////////////////// end of iterative process.. Re-arranging vector fields.. ...[DONE] ------------------------------------------------------------- ('[DONE] ..after ', -31.319732666015625, 'seconds ') -------------------------------------------------------------
tools.save(x, y, u, v, 0*v, 0*v, 'Y4-S3_Camera000398_widim2.txt' )
tools.display_vector_field('Y4-S3_Camera000398_widim1.txt', widim=True, scale=300, width=0.005)
tools.display_vector_field('Y4-S3_Camera000398_widim2.txt', widim=True, scale=300, width=0.005)
tools.display_vector_field('Y4-S3_Camera000398_a.txt', scale=300,
width=0.005,scaling_factor=1.)
(<Figure size 432x288 with 1 Axes>, <AxesSubplot:>)