In [1]:
# %load red_Cell.py
from openpiv import tools, pyprocess, scaling, filters, \
                    validation, process
import numpy as np
from skimage import data
import matplotlib.pyplot as plt

from scipy import ndimage
from skimage import feature
from PIL import Image
from pylab import *
%matplotlib inline
from skimage.color import rgb2gray
from skimage import img_as_ubyte

from pkg_resources import resource_filename as filename

frame_a  = tools.imread(filename('openpiv','examples/test3/Y4-S3_Camera000398.tif'))  
frame_b  = tools.imread(filename('openpiv','examples/test3/Y4-S3_Camera000399.tif'))


# for whatever reason the shape of frame_a is (3, 284, 256)
# so we first tranpose to the RGB image and then convert to the gray scale

frame_a = rgb2gray(frame_a)
frame_b = rgb2gray(frame_b)

plt.figure(figsize=(11,8))
plt.imshow(np.c_[frame_a,frame_b],cmap=plt.cm.gray)
Out[1]:
<matplotlib.image.AxesImage at 0x1279100a0>
In [2]:
# frame_a.dtype
In [3]:
#u, v, sig2noise = openpiv.process.extended_search_area_piv( frame_a, frame_b, window_size=24, overlap=12, dt=0.02, search_area_size=64, sig2noise_method='peak2peak' )
u, v, sig2noise = pyprocess.extended_search_area_piv( frame_a.astype(np.int32), frame_b.astype(np.int32), 
                                                     window_size=32, search_area_size=32,
                                                     overlap=8, dt=.1, 
                                                     sig2noise_method='peak2peak' )
x, y = pyprocess.get_coordinates( image_size=frame_a.shape, window_size=32, overlap=8 )
In [4]:
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 )
quiver(x,y,u,v)
plt.gca().invert_yaxis()
In [5]:
tools.save(x, y, u, v, mask, 'Y4-S3_Camera000398.txt' )
tools.display_vector_field('Y4-S3_Camera000398.txt', scale=3, width=0.0125)
# frame_vectors  = io.imshow(vectors)
In [6]:
x,y,u,v, mask = process.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', ' | ', [284, 256])
('     ', '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([11], dtype=int32))
('     ', 'Ncol', ' | ', array([10], dtype=int32))
('     ', 'Window sizes', ' | ', array([32], dtype=int32))
-----------------------------------
|           STARTING              |
-----------------------------------
('ITERATION # ', 0)
..[DONE]
(' --residual : ', 0.9999999602635717)
Starting validation..
..[DONE]
 
//////////////////////////////////////////////////////////////////
end of iterative process.. Re-arranging vector fields..
...[DONE]
-------------------------------------------------------------
('[DONE] ..after ', 53.85597491264343, 'seconds ')
-------------------------------------------------------------
In [11]:
tools.save(x, np.flipud(y), u, v, zeros_like(u), 'Y4-S3_Camera000398.txt' )
tools.display_vector_field('Y4-S3_Camera000398.txt', scale=300, width=0.005)
In [8]:
x,y,u,v, mask = process.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', ' | ', [284, 256])
('     ', '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([ 5, 11, 23, 23], dtype=int32))
('     ', 'Ncol', ' | ', array([ 5, 10, 21, 21], dtype=int32))
('     ', 'Window sizes', ' | ', array([64, 32, 16, 16], dtype=int32))
-----------------------------------
|           STARTING              |
-----------------------------------
('ITERATION # ', 0)
..[DONE]
(' --residual : ', 1.0000000125483464)
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.22727273012462418)
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.6429116349607981)
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 : ', 0.629290625745527)
Starting validation..
('Validation, iteration number ', 0)
 
('Validation, iteration number ', 1)
 
..[DONE]
 
//////////////////////////////////////////////////////////////////
end of iterative process.. Re-arranging vector fields..
...[DONE]
-------------------------------------------------------------
('[DONE] ..after ', 55.25097703933716, 'seconds ')
-------------------------------------------------------------
In [13]:
tools.save(x, np.flipud(y), u, v, zeros_like(u), 'Y4-S3_Camera000398.txt' )
tools.display_vector_field('Y4-S3_Camera000398.txt', scale=300, width=0.005)
In [ ]:
 
In [ ]: