#!/usr/bin/env python # coding: utf-8 # ## OpenPIV tutorial 2 # # In this notebook we compare the time to run the same analysis using Cython (precompiled) version # with the Python process using FFT and/or direct cross-correlation method # In[1]: from openpiv import tools, process, scaling, pyprocess, validation, filters import numpy as np import pylab get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: frame_a = tools.imread( '../test1/exp1_001_a.bmp' ) frame_b = tools.imread( '../test1/exp1_001_b.bmp' ) pylab.imshow(np.c_[frame_a,np.ones((frame_a.shape[0],20)),frame_b],cmap=pylab.cm.gray) # In[3]: get_ipython().run_cell_magic('time', '', "u, v, sig2noise = process.extended_search_area_piv( frame_a.astype(np.int32), frame_b.astype(np.int32), \n window_size=24, overlap=12, dt=0.02, \n search_area_size=64, \n sig2noise_method='peak2peak' )\nx, y = process.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=12 )\nu, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 2.5 )\nu, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2)\nx, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 )\ntools.save(x, y, u, v, mask, 'exp1_001_extended.txt' )\n") # In[4]: get_ipython().run_cell_magic('time', '', "u, v, sig2noise = pyprocess.extended_search_area_piv( frame_a, frame_b, corr_method='fft', \n window_size=24, overlap=12, dt=0.02, \n sig2noise_method='peak2peak' )\nx, y = pyprocess.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=12 )\nu, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 2.5 )\nu, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2.5)\nx, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 )\ntools.save(x, y, u, v, mask, 'exp1_001_fft.txt' )\n") # In[5]: get_ipython().run_cell_magic('time', '', "u, v, sig2noise = pyprocess.extended_search_area_piv( frame_a, frame_b, corr_method='direct', window_size=24, overlap=12, dt=0.02, sig2noise_method='peak2peak' )\nx, y = pyprocess.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=12 )\nu, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 2.5 )\nu, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2.5)\nx, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 )\ntools.save(x, y, u, v, mask, 'exp1_001_direct.txt' )\n") # In[6]: get_ipython().run_cell_magic('time', '', "# the pyprocess uses extended_search_area a bit different from the Cython version\n# the main difference is that we prepare as many windows as of the \n# search_area_size and inside those start with the small window of the \n# window_size. This creates a much coarser grid, but we do not need to \n# extrapolate with zeros for all the vectors outside the image. \n# Which approach is the right one, needs to be decided. \n\n\nwindow_size = 24\noverlap = 12\nsearch_area_size = 32\n\nu, v, sig2noise = pyprocess.extended_search_area_piv(frame_a, frame_b, \n window_size=window_size, \n overlap=overlap, \n dt=0.02, \n search_area_size=search_area_size, \n sig2noise_method='peak2peak' )\nx, y = pyprocess.get_coordinates( image_size=frame_a.shape, \n window_size=search_area_size, # note this point\n overlap=12 )\n") # In[7]: u, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 2.5 ) u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2.5) x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 ) tools.save(x, y, u, v, mask, 'exp1_001_pyprocess_extended.txt' ) # In[ ]: # In[8]: # in order to get the same denser field window_size = 16 overlap = 12 search_area_size = 24 u, v, sig2noise = pyprocess.extended_search_area_piv(frame_a, frame_b, window_size=window_size, overlap=overlap, dt=0.02, search_area_size=search_area_size, sig2noise_method='peak2peak' ) x, y = pyprocess.get_coordinates( image_size=frame_a.shape, window_size=search_area_size, # note this point overlap=overlap ) u, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 2.5 ) u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2.5) x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 ) tools.save(x, y, u, v, mask, 'exp1_001_pyprocess_extended_24.txt' ) # In[9]: tools.display_vector_field('exp1_001_extended.txt', scale=30, width=0.0025) tools.display_vector_field('exp1_001_direct.txt', scale=30, width=0.0025) tools.display_vector_field('exp1_001_fft.txt', scale=30, width=0.0025); tools.display_vector_field('exp1_001_pyprocess_extended.txt', scale=30, width=0.0025); tools.display_vector_field('exp1_001_pyprocess_extended_24.txt', scale=30, width=0.0025); # In[ ]: # In[ ]: # In[ ]: