You are on page 1of 21

PARTICLE IMAGE VELOCIMETRY (PIV):MATLAB

CODE DEVELOPMENT AND VALIDATION

submitted in partial fulfillment of the requirements


for the degree of

BACHELOR OF TECHNOLOGY
in
MECHANICAL ENGINNEERING
by

Y ROHITH RATNA KUMAR ME18B040


Y PRAMODH ME18B041

Supervisor(s)
Dr. BALAJI SUBRAMANIAN

DEPARTMENT OF MECHANICAL ENGINNEERING


INDIAN INSTITUTE OF TECHNOLOGY TIRUPATI
DECEMBER 2021
DECLARATION

We declare that this written submission represents our ideas in our own words
and where others’ ideas or words have been included, we have adequately cited and
referenced the original sources. we also declare that we have adhered to all principles of
academic honesty and integrity and have not misrepresented or fabricated or falsified
any idea/data/fact/source in our submission to the best of our knowledge. We understand
that any violation of the above will be cause for disciplinary action by the Institute and
can also evoke penal action from the sources which have thus not been properly cited or
from whom proper permission has not been taken when needed.

Place: Tirupati Signature


Date: 21-12-2021 Y ROHITH
ME18B040

Place: Tirupati Signature


Date: 21-12-2021 Y PRAMODH
ME18B041
BONA FIDE CERTIFICATE

This is to certify that the report titled PARTICLE IMAGE VELOCIMETRY


(PIV): MATLAB CODE DEVELOPMENT AND VALIDATION, submitted by Y
ROHITH and Y PRAMODH, to the Indian Institute of Technology, Tirupati, for the
award of the degree of B.Tech Degree, is a bona fide record of the project work done by
them under my supervision. The contents of this report, in full or in parts, have not been
submitted to any other Institute or University for the award of any degree or diploma.

Place: Tirupati Dr.BALAJI SUBRAMANIAN


Date: 21-12-2021 Guide
Assistant Professor
Department of Mechanical Engi-
neering
IIT Tirupati - 517501
ACKNOWLEDGMENTS

We would like to express to deepest appreciation and a sense of gratitude to our guide ,
Dr. Balaji Subramanian, department of Mechanical Engineering, Indian institute
technology Tirupati, along him we would also like to thank Shanthan Kumar Reddy, MS
Scholar.

i
ABSTRACT

KEYWORDS: PIV

This report highlights the approach and the progress in accomplishing the project.
Our project mainly deals with one of the flow visualization techniques Particle Image
Velocimetry (PIV). PIV can be divided into two parts, Image acquisition and Image
analysis. Our work involves only the image analysis part of the PIV. A basic working
code to visualize flow with an accuracy upto 2 decimals has been developed and validated
it with images from PIVLAB.

ii
TABLE OF CONTENTS

ACKNOWLEDGEMENTS i

ABSTRACT ii

LIST OF FIGURES iv

ABBREVIATIONS v

1 INTRODUCTION 1
1.1 Objectives and Scope . . . . . . . . . . . . . . . . . . . . . . . . . 1

2 Literature Review 2
2.1 Cross Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 FFT Cross correlation . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 5 point Gaussian surface fit . . . . . . . . . . . . . . . . . . . . . . 3

3 Description 5
3.1 Mathematical Formulation . . . . . . . . . . . . . . . . . . . . . . 5
3.2 Experimental Setup Materials Used . . . . . . . . . . . . . . . . . 6
3.3 Procedure, Techniques and Methodologies,etc . . . . . . . . . . . . 7
3.3.1 Window Shifting . . . . . . . . . . . . . . . . . . . . . . . 8

4 Results and Discussions 10

5 SUMMARY AND CONCLUSION 12


LIST OF FIGURES

1.1 PIV setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2.1 FFT Cross correlation . . . . . . . . . . . . . . . . . . . . . . . . . 3


2.2 5 pt. Gaussian Surface Fit . . . . . . . . . . . . . . . . . . . . . . . 4

3.1 Surface plot of the MQD function . . . . . . . . . . . . . . . . . . 6


3.2 Correlation Tracking . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 Evaluation error for ideal PIV recordings by using different algorithms
with a 64x64-pixel interrogation window . . . . . . . . . . . . . . 8
3.4 Window Shifting . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4.1 Comparison with PIVLAB output . . . . . . . . . . . . . . . . . . 10


4.2 Comparison with PIVLAB output . . . . . . . . . . . . . . . . . . 10
4.3 RMS Error vs Displacement . . . . . . . . . . . . . . . . . . . . . 11

iv
ABBREVIATIONS

PIV Particle Image Velocimetry


FFT Fast Fourier Transform
MQD Minimum Quadratic Difference
RMS Root Mean Square

v
CHAPTER 1

INTRODUCTION

Particle Image Velocimetry (PIV) is an optical measurement technique used to measure


velocity distribution in a plane of flow. Tracer particles are used to seed the flow as
they help in illuminating the flow with an optical setup and a high powered laser(like
Nd:YAG lasers). With high speed cameras which can capture two frames with a very
short time interval (a few hundred nano seconds) is used to capture images of the fluid
flow. These images are used to visualize the flow with the help of image analysis.

Figure 1.1: PIV setup

1.1 Objectives and Scope

Particle Image Velocimetry (PIV) is the standard technique which is used for flow mea-
surement in both fundamental research and for industrial applications. Its applications
are getting widened day by day. It has a vast scope from aerodynamic to biological
applications. It has become more intriguing in the recent years as volumetric velocity
measurements are made possible. In-house code helps us to have control over it and
customize it to our test conditions. Our objectives are to develop and validate an efficient
MATLAB code for PIV.
CHAPTER 2

Literature Review

2.1 Cross Correlation

In PIV, the main objective is to match the patterns in two images. This is done by a
technique called Cross Correlation. Basically, in signal processing, cross correlation is
where you take two signals and produce a third signal (correlated signal). This method is
a way to objectively compare different time series and allows you to see how two signals
match and where the best match occurs. In case of a 2-d matrix i.e., image, performing
2-d cross correlation on two images gives a correlation matrix.

The 2-D cross-correlation of an M×N matrix, X, and a P×Q matrix, H, is a matrix, C,


of size (M+P–1) × (N+Q–1). Its elements are given by

Elements of matrix C gives the information about correlation coefficients of X and H


Matrices. For example if X and H are give matrices,

After correlating both the matrices, a peak occurs in the correlation matrix C when
there is a best match between the matrices.
2.2 FFT Cross correlation

The standard cross correlation takes a lot of computational time(N 4 steps). So, FFT cross
correlation([N×log2 N]2 )which significantly reduces computational time is used as an
alternative. In FFT cross correlation the images are converted into frequency domain and
then complex conjugate multiplication is performed followed by conversion to spatial
domain to acquire correlation matrix. The entire FFT cross correlation method can be
represented as in figure 2.1.

Figure 2.1: FFT Cross correlation

2.3 5 point Gaussian surface fit

Usually, when we get a peak in correlation matrix and find its position to calculate
the displacement, the displacement will be accurate only up to a single pixel. This is
called Peak Locking effect. To achieve higher accuracies or to avoid this effect, 5 point
Gaussian surface fit is used. In which the correlation curve around the peak is always
assumed to be a Gaussian surface. Given by the equation 1, And then we take four points

around the peak where z2, z3, z4, z5 gives values of correlation matrix coefficients and
(x2, y2), (x3, y3), (x4, y4), (x5, y5) are their respective coordinates on matrix plane from
the origin O as shown in the figure 2.1. Similarly, the peak is given by (x1, y1, z1). Now

3
we solve for the 5 coefficients (c0, c1, c2, c3, c4) of the equation 1 by substituting the
above 5 points in equation 1. Once we get these coefficients, the 3D curve equation is
found. We later use differential calculus to find the true peak.

Figure 2.2: 5 pt. Gaussian Surface Fit

4
CHAPTER 3

Description

The mathematical formulation and the procedure we followed to attain the objective are
discussed here.

3.1 Mathematical Formulation

As we see in the above figure, suppose initially at time ’t’ in image G1 (x,y) a small
window of size M×N is given as GM . And when the time is t+∆t, the same window on
image G2 (x,y) is given by GS , with a shift of m pixels in x direction and n pixels in y
direction the total shift is represented as S where S is the resultant of m and n vectors.
Then the windows GM and GS are given as

GM (M,N) = G1 (xm -M/2+i,ym -N/2+j) = g1 (i,j)

GS (M,N) = G2 (xm -M/2+i+m,ym -N/2+j+n) = g2 (i+m,j+n)

Where xm and ym is the center of Gm . Where i and j change from 1 to M and 1 to N


respectively.

To compare the pattern in g1 (i,j) and g2 (i+m,j+n) we use a method called Minimum
Quadratic Difference (MQD) which is given by equation 2
1
D(m,n) = ∑M−1 ∑N−1 2
j=0 [g1 (i,j)-g2 (i+m,j+n)] → MinimumQuadraticDi f f erence(MQD)
M.N i=0
Figure 3.1: Surface plot of the MQD function

By using equation 2 we find MQD matrix(D(m,n)) from g1 and g2 matrices which will
have minimum peak when both the matrices match perfectly as shown in the figure 3.1.
We can also find the shift S from the location of the peak in terms of m and n, as S is the
resultant of m and n.

On further expanding the equation 2 and separating the only term with both g1 and g2
we get equation 2.1,

1 M−1 N−1
∑M−1 N−1
i=0 ∑ j=0 [g1 (i,j)-g2 (i+m,j+n)] = [∑ ∑ j=0 g1 (i,j)2 - M×N × D(m, n)+∑M−1
2 i=0 i=0

∑N−1 2
j=0 g2 (i+m,j+n) ]

Here, LHS is called the Correlation Term, and the matrix formed from this term is
called correlation matrix.

In case of correlation matrix, we get a maximum peak because we made the negative
term positive.

3.2 Experimental Setup Materials Used

As our work only deals with image analysis part, MATLAB software is used.

6
3.3 Procedure, Techniques and Methodologies,etc

Initially, two images are read and stored in a 3D array format. Later, we convert them
into gray scale images i.e., into 2D arrays. Then, some pre-processing techniques like
contrast adjustment and noise removal are performed. The de-noised images are now
padded in such a way that the size of the images are divisible by 64 so that we can
conveniently break the image into 128 or 64 or 32 sized windows with 50% overlap
in both x and y directions. Now the image 1 is divided into 32 sized windows with
50% overlap and the image 2 is divided into 64 sized windows with 75% overlap in
such a way that every 32 sized window in image 1 except for the windows at the border
has a 64 sized window in image 2 with the same center as the corresponding 32 sized
window. Now, the 32 sized windows are zero padded into 64 sized windows and FFT
cross correlation is performed with corresponding 64 sized windows in image 2 to get
the shifts.

This is done because sometimes the patterns might leave the windows. So, to increase
the search area a 64 sized window is taken around a 32 sized window as shown in figure
3.2. This technique is called Correlation Tracking.

Figure 3.2: Correlation Tracking

7
If the RMS errors for the methods FFT correlation method, MQD method, and correlation
tracking method are compared from the figure 3.3, it seems that MQD method is the
best method. However, it takes a lot of computational time. So, the next best alternative
appears to be Correlation Tracking, as the error is continuously increasing in FFT
correlation method. But, for displacements very close to zero FFT correlation has the

Figure 3.3: Evaluation error for ideal PIV recordings by using different algorithms with
a 64x64-pixel interrogation window

least error. So, if the measuring method is somehow made a null measurement technique
then FFT correlation is the best method both in terms of computational time and accuracy.

The technique which is used to convert the measurement into a null type is called
Window Shifting.

3.3.1 Window Shifting

Window shifting is an iterative process in which the shifts calculated in the previous
iteration are used in the present iteration to shift the windows in image 2 by their
respective shifts in previous iteration. As a result the shift in each iteration keeps
reducing and converges to zero, making it a null type measurement. For example, in the
figure 3.4, the previous shift is SW S so the window is shifted by SW S to get the new shift
S’ and the total shift is given by S = S’ + SW S

8
Figure 3.4: Window Shifting

However, for the first iteration, which gives the first estimate of shifts, window
shifting cannot be done as there is no previous iteration. This is the reason correlation
tracking is done for the first iteration as discussed at the start of this chapter.

For the second iteration both the padded images are divided into 32 sized windows
with 50% overlap in both directions. Now the shifts from previous iteration corre-
sponding to each 32 sized windows are used to shift the windows on the second image
accordingly. Then again FFT correlation is done and the peaks are located followed by a
5 point Gaussian surface fit to get more accurate peak locations and shifts corresponding
to second iteration. This process is repeated until the shifts converge to zero. And the
shifts of every iteration are added to find the total shifts. Finally, these total shifts are
plotted to visualize the flow.

9
CHAPTER 4

Results and Discussions

For a synthetic image of pure translation of 5.23 pixels, the output is shown in figure
4.1(a). An almost same output is yielded.

(a) Our output (b) PIVLAB output

Figure 4.1: Comparison with PIVLAB output

For a synthetic image of a Rankine vortex, the output is shown in figure 4.2(a). A
similar output is yielded with few error vectors.

(a) Our output (b) PIVLAB output

Figure 4.2: Comparison with PIVLAB output


The following plot (Fig. 4.3) shows the RMS errors against particle displacements
of the code. RMS errors are calculated for images with displacements 5.0, 5.1, ... , 6.0
pixels.

Figure 4.3: RMS Error vs Displacement

A high RMS is observed at 5.5 compared to other points as correlation tracking is used
in iteration (correlation tracking is known to have high errors at 0.5 pixel displacement).

11
CHAPTER 5

SUMMARY AND CONCLUSION

A basic working PIV code is achieved. However, still effects like shear and rotation are
to be accounted for. The code works for any set of images with no shear and rotation
effects. An accuracy up to 2 decimals is achieved. Future work includes implementing
window deformation to account for shear effects and also central difference method will
be used to calculate the velocities.
REFERENCES
1. https://observablehq.com/@lemonnish/cross-correlation-of-2-matrices
2. http://publish.illinois.edu/piv15conference/scope/
3. Steven T. Wereley (Spring, 2014). [Fundamentals of Particle Image Velocimetry].
https://nanohub.org/resources/20295series.
4. L. Gui el al. A comparative study of the MQD method and several correlation-based
PIV (2000). Iowa City, USA.
5. Markus Raffel et al. Particle Image Velocimetry A Practical Guide. Germany, 2018‘
6. https://www.photonics.com/Articles/Particle_Image_Velocimetry_Basics_Developments/a25121

13

You might also like