Image Processing Reference
In-Depth Information
%Optical flow by correlation
%d: max displacement., w: window size 2w+1
function FlowCorr(inputimage1,inputimage2,d,w)
%Load images
L1=double(imread(inputimage 1, 'bmp'));
L2=double(imread(inputimage2,'bmp'));
%image size
[rows, columns]=size(L1); %L2 must have the same size
%result image
u=zeros(rows, columns);
v=zeros(rows, columns);
%correlation for each pixel
for x1=w+d+1:columns-w-d
for y1=w+d+1:rows-w-d
min=99999; dx=0; dy=0;
%desplacement position
for x2=x1-d:x1+d
for y2=y1-d:y1+d
sum=0;
for i=-w:w% window
for j=-w:w
sum=sum+(double(L1(y1+j,x1+i))-
double(L2(y2+j,x2+i)))^2;
end
end
if (sum<min)
min=sum;
dx=x2-x1; dy=y2-y1;
end
end
end
u(y1,x1)=dx;
v(y1,x1)=dy;
end
end
%display result
quiver(u,v,.1);
Code 4.20
Implementation of area-based motion computation
window increases, the result is smoother, but we lose detail about the boundary of the
object. We can also observe that when the window is small, they are noisy displacements
near the object's border. This can be explained by considering that Equation 4.70 supposes
that pixels appear in both images, but this is not true near the border since pixels appear and
disappear (i.e. occlusion) from and behind the moving object. Additionally, there are
Search WWH ::




Custom Search