#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().system('pip install imageio numpy matplotlib') get_ipython().system('pip install -e .') # In[2]: from openpiv_python_lite import extended_search_area_piv as piv, get_coordinates, random_noise # In[3]: import numpy as np frame_a = np.zeros((32, 32)) frame_a = random_noise(frame_a) frame_b = np.roll(np.roll(frame_a, 3, axis=1), 2, axis=0) threshold = 0.1 def test_piv_32(): """ test of the simplest PIV run 32 x 32 """ u, v = piv(frame_a, frame_b, window_size=32) assert(np.abs(u-3) < threshold) assert(np.abs(v+2) < threshold) def test_piv_16_32(): """ test of the search area larger than the window """ u, v = piv(frame_a, frame_b, window_size=16, search_area_size=32) assert(np.abs(u[0,0]-3) < threshold) assert(np.abs(v[0,0]+2) < threshold) # In[4]: test_piv_32() # In[5]: test_piv_16_32() # In[6]: import imageio def test_piv(): """ Simplest PIV run on the pair of images using default settings piv(im1,im2) will create a tmp.vec file with the vector filed in pix/dt (dt=1) from two images, im1,im2 provided as full path filenames (TIF is preferable, whatever imageio can read) """ # if im1 is None and im2 is None: im1 = ('./test/img/frame_a.tif') im2 = ('./test/img/frame_b.tif') frame_a = imageio.imread(im1) frame_b = imageio.imread(im2) frame_a[0:32, 512-32:] = 255 print(frame_a[0,0]) u, v = piv(frame_a,frame_b, window_size=32,overlap=16) x, y = get_coordinates(image_size = frame_a.shape, window_size=32, overlap=16) print(x[0], y[0], u[0], v[0]) return x, y, u, v # In[7]: x,y,u,v = test_piv() # In[8]: import pylab # In[9]: pylab.quiver(x,y,u,-v) # In[ ]: