Code covered by the BSD License

# PTVlab (Particle Tracking Velocimetry - lab)

by

### AntoineP (view profile)

A GUI based tool to preprocess, analyze, validate, postprocess, visualize and simulate PTV data.

```function [X Y Usup Vsup InMask] = ptv2grid(x,y,u,v,currentimage,roirect,res,idx,maskiererx,maskierery)
%PTV2GRID Lay down the vectors from PTV on a regular grid

%   Copyright, Antoine Patalano Jul 04, 2012
%   antoine.patalano@gmail.com

%   INPUT:
%   x and y data: a cell in the form xydata = {XvaluesOfCoordinates YvaluesOfCoordinates}.
%   u and v: a cell in the form uvdata= {UvaluesOfCVelocity YvaluesOfVelocity}.
%   roirect: region of interest
%   res: size of a element. ex:16 (in pixels)
%   OUTPUT:
%   X and Y: a 2D matrix with X and Y coordinates
%   Usup and Vsup: a 2D matrix with U and V velocities

%%
%define the limit of the ROI
if  isempty(roirect)==1    %
bordmaxx=size(currentimage,2);
bordmaxy=size(currentimage,1);
bordminx=0;
bordminy=0;
else
bordmaxx=roirect(3)+roirect(1);
bordmaxy=roirect(4)+roirect(2);
bordminx=roirect(1);
bordminy=roirect(2);
end
%define the grid with the size of the element
xgrid=bordminx:res:bordmaxx;
ygrid=bordminy:res:bordmaxy;

% figure
[X,Y]=meshgrid(xgrid,ygrid);
Usup=nan*X;
Vsup=Usup;
ClustersAsgd=unique(idx);
for i=1:length(ClustersAsgd)
if length(find(idx==ClustersAsgd(i)))>2 % check if there are more than
%2 points in one cluster, if not the they won't be interpolated on
%the grid because you need at least 3 points
try % for the newest version of MATLAB
FU=TriScatteredInterp(x(idx==ClustersAsgd(i)),y(idx==ClustersAsgd(i)),u(idx==ClustersAsgd(i)));
FV=TriScatteredInterp(x(idx==ClustersAsgd(i)),y(idx==ClustersAsgd(i)),v(idx==ClustersAsgd(i)));
U=FU(X,Y);
V=FV(X,Y);
catch
U = griddata(x(idx==ClustersAsgd(i)),y(idx==ClustersAsgd(i)),u(idx==ClustersAsgd(i)),X,Y);
V = griddata(x(idx==ClustersAsgd(i)),y(idx==ClustersAsgd(i)),v(idx==ClustersAsgd(i)),X,Y);
end
Usup(isnan(U)==0)=U(isnan(U)==0);% Usup and Vsup are the matrix U and V of each clusters superposed together
Vsup(isnan(V)==0)=V(isnan(V)==0);

end
end

p=[ reshape(X,size(X,1)*size(X,2),1),reshape(Y,size(Y,1)*size(Y,2),1)];
n      = size(node,1);
cnect  = [(1:n-1)' (2:n)'; n 1];
inside=inpoly(p,node,cnect);

end
end