Instructor: Lichuan Gui lichuan-gui@uiowa
description
Transcript of Instructor: Lichuan Gui lichuan-gui@uiowa
Measurements in Fluid Mechanics058:180 (ME:5180)
Time & Location: 2:30P - 3:20P MWF 3315 SC
Office Hours: 4:00P – 5:00P MWF 223B-5 HL
Instructor: Lichuan [email protected]
Phone: 319-384-0594 (Lab), 319-400-5985 (Cell) http://lcgui.net
2
Lecture 26. Sub-pixel Displacement
3
Correlation Interrogation & FFT Acceleration
Evaluation function
Auto-correlation function
g(i,j)
0
0.2
0.4
0.6
0.8
1
(m,n)
-30-20
-100
1020
30
m
-30-20
-100
1020
30
n
M
i
N
j
njmigjignm1 1
,,,
(m*=10, n*=-5) (m*=-10, n*=5)
- One double exposed evaluation sample, i.e. g(i,j)=g2(i,j)=g1(i,j)
- Displacement determined by positions of the secondary maxima
- Two possible velocity directions
4
Correlation Interrogation & FFT Acceleration
Evaluation function
Cross-correlation function
- Two single exposed evaluation samples, i.e. g2(i,j) & g1(i,j)
0
0.2
0.4
0.6
0.8
1
(m,n)
-30-20
-100
1020
30
m
-30-20
-100
1020
30
n
M
i
N
j
njmigjignm1 1
21 ,,,
(m*=3, n*=5)
g1(i,j)
g2(i,j)
- Velocity direction clear
- Displacement determined by position of the maximum
5
Sub-pixel Displacement
Local surface fit of evaluation function
Discrete correlation function around point of maximum (m*,n*)
-1
-1
6
Sub-pixel Displacement
Local surface fit of evaluation function
Discrete distribution fitted with continuous surface z(x,y)
7
Sub-pixel Displacement
Local surface fit of evaluation function
Sub-pixel displacement (x*,y*) determined with position of the maximum of z(x,y)
8
Sub-pixel Displacement
Local surface fit of evaluation function
5-point fit most commonly used
9
Sub-pixel Displacement
Local surface fit of evaluation function
5-point parabolic fit
Fit function 2
42
3210),( xcycxcyccyxz
Linear equation system for determining constants
0,1
0,1
1,0
1,0
0,0
10101
10101
01011
01011
00001
**
**
**
**
**
4
3
2
1
0
nm
nm
nm
nm
nm
c
c
c
c
c
02
02*
31
*42
ycc
xcc
1,21,2,4
1,1,
,12,12,4
,1,1
******
*****
******
*****
nmnmnm
nmnmy
nmnmnm
nmnmx
0,
,
0,
,
**
**
yxy
yxz
yxx
yxz
Position of the maximum
10
Sub-pixel Displacement
Local surface fit of evaluation function
5-point exponential fit (3-point Guassian curve fit)
0,
,
0,
,
**
**
yxy
yxz
yxx
yxz
Position of the maximum
Fit function 2
42
3210),( xcycxcycceyxz
Linear equation system for determining constants
0,1ln
0,1ln
1,0ln
1,0ln
0,0ln
10101
10101
01011
01011
00001
**
**
**
**
**
4
3
2
1
0
nm
nm
nm
nm
nm
c
c
c
c
c
1,ln21,ln2,ln4
1,ln1,ln
,1ln2,1ln2,ln4
,1ln,1ln
******
*****
******
*****
nmnmnm
nmnmy
nmnmnm
nmnmx
11
Arbitrarily sized interrogation window
Performance of FFT-based correlation
- Effective correlation region
A : Effective correlation region
B,C,D: Periodically Padded regions
DCBA
M
i
N
j
njmigjignm
1 1
21 ,,,
12
Arbitrarily sized interrogation window
Performance of FFT-based correlation- Reliability & RMS error dependent on particle image displacement
- Reliability & RMS error dependent on interrogation window size
- Impossible to determine displacement components not less than half of
window side length
total
valid
N
NReliability:
RMS error:
validN
kkk
valid
SSN 1
21
S : measured valueS’: real value
Some test results with synthetic images
f: interrogation window size
0 4 8 12 16 20 24 28 320
0.2
0.4
0.6
0.8
1
0 4 8 12 16 20 24 28 320
0.1
0.2
0.3
0.4
0.5
f =64X64
f =32X32
16X16
f =64X64
f =16X16
f =32X32
S
S
13
Arbitrarily sized interrogation window
Average padding to next power of 2
22
22
2
21
1
*
*
N
Mfor
N
M
* *
1 1
*2
*1
* ,,,M
i
N
j
njmigjignm
NjMijigjig 0,1,,*
**
**
1 1
*
,1
1,
,1
,
NjNMi
or
NjMiM
qpgMN
jigM
p
N
q
3,2,1,0,for,, **** lkjiglNjkMig
Test results with synthetic
images (f=32x32)
1 original
2 padded to f=64x64
0 5 10 15 20 250
0.1
0.2
0.3
0.4
0.5
0 5 10 15 20 250
0.2
0.4
0.6
0.8
1
1
2
1 2
S S
14
More about Correlation Interrogation
Fast computation of evaluation functionAcceleration with radix-2 based FFT algorithm- Computation time test
15
Effect of linear transformation of evaluation samples
211 1
2121 1
12121 ,,,, BBnjmigBAjigBAnmAAnmM
i
N
j
M
i
N
j
jigjig ,,, 21
2222
1111
,,
,,
BjigAjig
BjigAjig
jigjig ,,, 21
M
i
N
j
njmigjignm1 1
21 ,,,
M
i
N
j
njmigjignm1 1
21 ,,,
DnmCnm ,,
More about Correlation Interrogation
on the correlation function
- no influence
16
Effect of linear transformation of evaluation samples
More about Correlation Interrogation
on the sub-pixel displacement determination with Parabolic surface/curve fit
- no influence
DnmCnm ,,
nmx
mnmnm
nmnm
DmCDnmCDnmC
DnmCDnmC
mnmnm
nmnmnmx
,
0,12,12,4
,1,1
0,12,12,4
,1,1
0,12,12,4
,1,1,
*
*****
****
*****
****
*****
*****
17
Effect of linear transformation of evaluation samples
More about Correlation Interrogation
on the sub-pixel displacement determination with exponential surface/curve fit
DnmCnm ,,
0,1ln2,1ln2,ln4
,1ln,1ln
0,1ln2,1ln2,ln4
,1ln,1ln*****
****
*****
****
mnmnm
nmnm
mnmnm
nmnm
nmxnmx ,, **
- obvious influence
- no zero and negative values allowed
- normalization suggested before sub-pixel fit
Class project: example of Matlab functions for PIV recording evaluation File name: correlation.m
function[c m n]=correlation(g1,g2)% INPUT PARAMETERS% g1 - 1st evaluation sample, g2 - 2nd evaluation sample% OUTPUT PARAMETERS% c - correlation function, % m - horizontal coordinate, n - vertical coordinate
[M N]=size(g1); % determine size of evaluation sample for k=3:12 % determine window size for FFT - begin if 2^k>=M & 2^k>=N break; endendM2=2^k;N2=2^k; % determine window size for FFT - end
gm1=mean(mean(g1)); % average gray value padding - begin gm2=mean(mean(g2));for i=1:M2 for j=1:N2 if i<=M & j<=N gg1(i,j)=g1(i,j); gg2(i,j)=g2(i,j); else gg1(i,j)=gm1; gg2(i,j)=gm2; end endend % average gray value padding - end
gfft1=fft2(gg1); % compute correlation function - begingfft2=conj(fft2(gg2));C=real(ifft2(gfft1.*gfft2)); % compute correlation function - end
for i=1:M2 % determine coordinates in correlation plane - begin for j=1:N2 m(i,j)=i-M2/2-1; n(i,j)=j-N2/2-1; endend % determine coordinates in correlation plane - end
for i=1:M2 % periodical reconstruction - begin for j=1:N2/2 t=C(i,j); C(i,j)=C(i,N2-j+1); C(i,N2-j+1)=t; endendfor j=1:N2 for i=1:M2/2 t=C(i,j); C(i,j)=C(M2-i+1,j); C(M2-i+1,j)=t; endendfor i=1:M2/2 C1(i,1:N2)=C(i+M2/2,1:N2);endfor i=M2/2+1:M2 C1(i,1:N2)=C(i-M2/2,1:N2);endfor j=1:N2/2 c(1:M2,j)=C1(1:M2,j+N2/2);endfor j=N2/2+1:N2 c(1:M2,j)=C1(1:M2,j-N2/2);end % periodical reconstruction of correlation function - end
18
19
Class project: example of Matlab functions for PIV recording evaluation File name: peaksearch.mfunction [cm vx vy]=peaksearch(C,m,n,sr,mode,direction)% INPUT PARAMETERS% C - correlation function% m - horizontal coordinate% n - vertical coordinate% sr - search radius % mode - (=0) cross-correlation, (=1) auto-correlation% direction - 1. to right, 2. to left, 3. upwards, 4. downwards% OUTPUT PARAMETERS% cm - high correlation peak value% (vx,vy) – particle image displacement [M N]=size(C); % high peak search - beginix=0;jy=0;cm=0;for i=M/2+1-sr:M/2+1+sr for j=N/2+1-sr:N/2+1+sr if mode==1 & direction==1 & i<=M/2+1 continue; end if mode==1 & direction==2 & i>=M/2+1 continue; end if mode==1 & direction==3 & j>=N/2+1 continue; end if mode==1 & direction==4 & j<=N/2+1 continue; end
max=0; for i1=i-1:i+1 for j1=j-1:j+1 if max<C(i1,j1) max=C(i1,j1); end end end if C(i,j)>=max & C(i,j)>cm ix=i; jy=j; cm=C(i,j); end endendmm=m(ix,jy);nn=n(ix,jy);% high peak search -end
% SUB-PIXEL FITdx=(log(C(ix+1,jy))-log(C(ix-1,jy)))/(4*log(C(ix,jy))-2*log(C(ix+1,jy))-2*log(C(ix-1,jy)));dy=(log(C(ix,jy+1))-log(C(ix,jy-1)))/(4*log(C(ix,jy))-2*log(C(ix,jy+1))-2*log(C(ix,jy-1)));
%Displacementvx=mm+dx;vy=nn+dy;
20
Class project: example of Matlab functions for PIV recording evaluation File name: sample01.m
function[g]=sample01(G,M,N,X,Y)%INPUT PARAMETERS% G - gray value distribution of the PIV recording% M - interrogation sample width% N - interrogation sample height% X, Y - interrogation sample coordinates% ----------------------------------------------------% OUTPUT PARAMETERS% g - gray value distribution of the evaluation sample% ----------------------------------------------------% I, J – integer part of evaluation sample coordinates% x,y – decimal part of evaluation sample coordinates
[nx ny]=size(G);
I=int16(X); % integer part of coordinatesJ=int16(Y);
x=double(X)-double(I); %decimal part of coordinates
y=double(Y)-double(J);
if x<0 I=I-1; x=x+1; % x should be positiveend
if y<0 J=J-1; y=y+1; % y should be positive end
gm=0; % initial value of mean gray valuenr=0; % initial value of number of effective pixelsfor i=1:M for j=1:N ii=i+I-int16(M/2); jj=j+J-int16(N/2); if ii>=1 & ii<nx & jj>=1 & jj<ny % pixels in the image frame Ga=double(G(ii,jj)); Gb=double(G(ii+1,jj)); Gc=double(G(ii,jj+1)); Gd=double(G(ii+1,jj+1)); A=(1-x)*(1-y); B=x*(1-y); C=(1-x)*y; D=x*y; g(i,j)=A*Ga+B*Gb+C*Gc+D*Gd; % bilinear interpolation gm=gm+g(i,j); nr=nr+1; % count effective pixels else g(i,j)=-1; % pixels out of image frame end endendgm=gm/double(nr); % determine mean gray value
for i=1:M for j=1:N if g(i,j)<0 g(i,j)=gm; % fill with mean value end endend
21
Class project: example of Matlab functions for PIV recording evaluation File name: img2xy.m
function [G]=img2xy(A)% A - image% G - gray value distribution[ny nx]=size(A);for x=1:nx for y=1:ny G(x,y)=A(ny-y+1,x); endend
File name: xy2img.m
function [A]=xy2img(G)% A - image% G - gray value distribution[nx ny]=size(G);Gmax=max(max(G));Gmin=min(min(G));for x=1:nx for y=1:ny A(ny-y+1,x)=int8(double(G(x,y)-Gmin)/double(Gmax-Gmin)*245+5); endend
22
Class project: example of Matlab functions for PIV recording evaluation File name: main.m
clear;A=imread('D001_1.bmp'); % input image file G=img2xy(A); % conver image to gray value distribution
% evaluation pointx=100;y=200;
% interrogation window size M=64;N=64;
% evaluation samples g1=sample(G,M,N,x,y);g2=g1;
% correlation function[C m n]=correlation(g1,g2);
sr=20; % search radiusmode=1; % PIV recording modedirection=1; % main flow direction[cm vx vy]=peaksearch(C,m,n,sr,mode,direction) % particle image displacement
D=xy2img(C); % convert correlation function to imageimshow(D); % display correlation function