piv_handling#
Example Usage#
Full Contents:#
- piv_handling.GetPIV(im1, im2, X1, Y1, EdgeLength, histequilize)#
GetPIV computes PIV flow field estimate based on image1 (im1) and image2 (im2) using the Phase Correlation method implemented in xcorr2fft. im1 & im2 are assumed to have the same dimensions. The grid X1,Y1 is assmued to be contained in the image domain with finite EdgeLength defining size of PIV box. Output are components of the flow fiel on the grid
Written by: Sebastian J Streichan, KITP, February 01, 2013 NPM added histeq step (optional)
- piv_handling.PIVScript#
Using GetPIV we computes the flow field estimate based on an image sequence im1 & im2 are assumed to have the same dimensions. The grid X1,Y1 is assmued to be contained in the image domain with finite EdgeLength defining size of PIV box. This script generates a movie displaying the original image with flow field overlayed.
Written by: Sebastian J Streichan, KITP, February 14, 2013 NPM added histequalize option on 27
- piv_handling.PIVTimeseries(inputDir, options)#
Using GetPIV we computes the flow field estimate based on an image sequence im1 & im2 are assumed to have the same dimensions. The grid X1,Y1 is assmued to be contained in the image domain with finite EdgeLength defining size of PIV box. This script generates a movie displaying the original image with flow field overlayed.
Written by: Sebastian J Streichan, KITP, February 14, 2013 NPM added histequalize option and made function
- piv_handling.advectRuntStripes#
test script
- piv_handling.advectRuntStripes_script#
test script
- piv_handling.applyOpticalFlow(pivStack, im0, Options)#
- Parameters
Options (
struct with fields) –- mandatory fields:
outDir minT maxT
- optional fields:
- plot_texturepathsbool (default=true)
make movie of optical flow
- plot_scatterpathsbool (default=false)
make movie of tracer beads
- clipImagebool (default=true)
clip the texturepatch image to a rectangle
szX : size of resampled images in which PIV is performed szY : size of resampled images in which PIV is performed X0 : evaluation grid points, x coord Y0 : evaluation grid points, y coord
2021 (
NPMitchell) –
- piv_handling.extractMetricFromPIVPair(VX, VY, WX, WY, computation_method, truncation_factor)#
Extract a comparison metric from computation on two 2D PIV fields V,W returning a matrix of metric values calculated at all points in the field. VX, VY, WX, WY are assumed to have the same dimensions. The field will be spatially truncated if truncation_factor is not 0. The method of computation used is specified by piv_computation_method. The dimension to truncate is given by truncation_dim (1 or 2) The factor to truncate the image by, on both sides, is given by truncation_factor. The default dimension is 2, the horizontal axis of the image i.e. the vertical axis of the PIV field (the PIV program transposes the image when computing PIV to be symmetric about the vertical axis). Also returns the minimum and maximum time indices used along the truncation dimension, the matrix values outside of that range should all be zeros.
Modified on 8/31 to input V_RMS and W_RMS as the RMS values for the given fields, where smoothed and truncated RMS values can be taken into account rather than simply the standard calculation.
- Parameters
VX (
X component of first PIV field (V), 2D matrix) –VY (
Y component of first PIV field (V), 2D matrix) –WX (
X component of second PIV field (W), 2D matrix) –WY (
Y component of second PIV field (W), 2D matrix) –computation_method (
string with potential values) – normalized residual unnormalized residual inner producttruncation_dim_img (
dimension to truncate over, int with value 1 or 2,) –2 (
default dimension) –truncation_factor (
double factor to truncate matrix by on both sides,) –(exclusive) (
must be between 0 (inclusive) and 0.5) –Returns – MetricMat, a 2D matrix of correlation values calculated based on the chosen method.
Outputs –
------- –
2020 (
Vishank Jain-Sharma) –
- piv_handling.getPIVLab(im1, im2, options)#
[uu, vv, u_filt, v_filt, xx, yy] = getPIVLab(im1,im2,options)
getPIVLab computes PIV flow field estimate based on image1 (im1) and image2 (im2) using the Phase Correlation method implemented in PIVLab. im1 & im2 are assumed to have the same dimensions. Output are components of the flow field on the grid (xx, yy)
- Parameters
im1 (
NxM numeric) – image at t0im2 (
NxM numeric) – image at t0 + deltaToptions (
optional struct with optional fields) – intArea1 subpixFindr mask roi numPasses intArea2 intArea3 intArea4 repeat disAuto clahe claheW highPass highPassSz clipping wiener wienerW valid_vel do_stdev_check stdthres do_local_median neigh_thres
- Returns
uu (PxQ float) – velocity in x
vv (PxQ float) – velocity in y
u_filt (PxQ float) – velocity in x
v_filt (PxQ float) – velocity in y
xx (PxQ float) – evaluation points in x
yy (PxQ float) – evaluation points in y
Written by NPMitchell 2022
- piv_handling.processMedFiltersScript#
script to run med filters on PIV data
- piv_handling.pullbackPathlines(QS, x0, y0, t0, options)#
Create paths in pullback space (in pixels, XY) by following optical flow of PIV measured on standardized pullback map. Note: I’ve chosen to use spatial smoothing via Gaussian blur rather than temporal smoothing of velocities for this code.
- Parameters
pivStack (
struct with two #TP x nX x nY float entries) –- vx: #TP x nX x nY float
velocities in x direction
- vy: #TP x nX x nY float
velocities in y direction
x0 (
n*m float array) – x coordinates in pullback pixels to start pathlines at t0y0 (
n*m float array) – y coordinates in pullback pixels to start pathlines at t0t0 – time at which to begin the pathlines, must be member of QS.xp.fileMeta.timePoints
options (
struct with fields) –- previewbool
view intermediate results
- timePoints1d int array
the timpepoints along which to map pathlines that intersect with (x0, y0) at t0
- Returns
XX (#timePoints x size(x0, 1) x size(x0, 2) float array) – the pullback pixel X coordinates of the pathline spanning timePoints
YY (#timePoints x size(x0, 1) x size(x0, 2) float array) – the pullback pixel Y coordinates of the pathline spanning timePoints
NPMitchell 2021
- piv_handling.rk4DynamicVelocity2D(pts, X0v, Y0v, vx, vy, hh, tt)#
[xyOut, xyPaths] = rk4DynamicVelocity2D(pts, XY0v, v2d, hh, tt) solve Runge-Kutta 4th order in 2d space with fixed velocity field
- Parameters
pts (
Px2 numeric) – points at which we begin tracing paths in 2dXY0v (
MxN numeric) – evaluation points at which velocities residevx (
TxMxN numeric) – dynamic 2d velocity in x at evaluation points (time, vxgridX, vxgridY)vy (
TxMxN numeric) – dynamic 2d velocity in y at evaluation points (time, vygridX, vygridY)hh (
optional float 0<h<1 (default=0.05)) – stepsize for finding pathtt (
optional Qx1 float array (default=0:hh:size(v2d, 1))) – timestamps relative to the indices of v2d at which to compute
- Returns
xyOut (Px2 float) – final positions
xyPaths (length P cell array) – paths from pts to xyOut
NPMitchell 2022
- piv_handling.rk4FixedVelocity2D(pts, X0v, Y0v, vx, vy, hh, tt)#
[xyOut, xyPaths] = rk4FixedVelocity2D(pts, XY0v, v2d, hh, tt) solve Runge-Kutta 4th order in 2d space with fixed velocity field
- Parameters
pts (
Px2 numeric) – points at which we begin tracing paths in 2dXY0v (
MxN numeric) – evaluation points at which velocities residev2d (
MxN numeric) – 2d velocity at evaluation pointshh (
float 0<h< 1) – stepsize for finding path
- Returns
xyOut (Px2 float) – final positions
xyPaths (length P cell array, such that xyPaths{i} is #ttx2 float array) – paths from pts to xyOut
NPMitchell 2022
- piv_handling.runMedianFilterOnPIVField(input_PIV_path, output_path)#
Runs a median filter on the PIV data located in input_PIV_path and saves the data to output_path
- Parameters
input_PIV_dir (
path to directory containing all the PIV .mat structures) –output_dir (
path to directory in which to save median filtered PIV) –median_order (
order of median filter--total range to take median over) –Outputs –
fields (
new directory with name output_directory that containts saved PIV) –filter (
which have been run through median) –
Vishank Jain-Sharma 2020, edits NPMitchell 2022
- piv_handling.xcorr2fft(image1, image2)#
xcorr2fft computes offsets between images image1 and image2 based on Phase Correlation method. image1 & image2 are assumed to have the same dimensions.
Written by: Sebastian J Streichan, EMBL, February 29, 2012