Professional Documents
Culture Documents
Tracking Using K Filter
Tracking Using K Filter
2006-2007
PROJECT REPORT
BACHELOR OF TECHNOLOGY
IN
ELECTRONICS AND COMMUNICATION ENGINEERING
SUBMITTED BY
1
Acknowledgements
2
CONTENTS
Abstract
Introduction
Kalman Filter
State-space Representation
Underlying Dynamic System Model
Code
Results
Conclusions
References
3
2D TARGET TRACKING USING KALMAN FILTER
Sahil Sandhu Devender Budhwar Amit Kumar Karna
¾ B.Tech (E.C.E.) ¾ B.Tech (E.C.E.) ¾ B.Tech (E.C.E.)
National Institute of National Institute of National Institute of
Technology Warangal Technology Warangal Technology Warangal
sahilsandhu@gmail.com dev.budhwar@gmail.com karnamit@gmail.com
4
(optimal Kalman gain)
5
At each timestep the Jacobian is evaluated with
current predicted states. These matrices can be
used in the Kalman filter equations. This process However, when the Kalman filter is used to
essentially linearizes the non-linear function estimate the state x, the probability distribution
around the current estimate. of interest is that associated with the current
This results in the following extended Kalman states conditioned on the measurements up to the
filter equations: current timestep. (This is achieved by
Predict marginalizing out the previous states and
dividing by the probability of the measurement
set.)
This leads to the predict and update steps of the
Update
Kalman filter written probabilistically. The
probability distribution associated with the
predicted state is product of the probability
distribution associated with the transition from
the (k − 1)th timestep to the kth and the
probability distribution associated with the
Where the state transition and observation previous state, with the true state at (k − 1)
matrices are defined to be the following integrated out.
Jacobians
is a normalization term.
The remaining probability density functions are
Using these assumptions the probability The scanning in a frame is from the top left to
distribution over all states of the HMM can be the bottom right. The motion vector of a
written simply as: macroblock can be predicted from that of its left
spatial neighbour. The measured motion vectors
6
are obtained through a conventional three step motion estimate V(k/k) when the assumption
procedure. of smooth changes is not strictly valid. As a
result, it is expected that we have a better
In the same manner as in, the intraframe motion motion estimate for the 8x8-motion
estimation process is mlodelled through an auto- compensation procedure.
regressive model which produces the state-space
equations.
4.0 Underlying dynamic system model
From this macroblock-based representation
how do we define the 8x8-block: based Kalman filters are based on linear dynamical
representation? Each 16x16-block yields a systems discretised in the time domain. They are
zig-zag sequence of four 8x8 blocks: modelled on a Markov chain built on linear
operators perturbed by Gaussian noise. The state
of the system is represented as a vector of real
numbers. At each discrete time increment, a
linear operator is applied to the state to generate
the new state, with some noise mixed in, and
optionally some information from the controls on
the system if they are known. Then, another
linear operator mixed with more noise generates
the visible outputs from the hidden state. The
Kalman filter may be regarded as analogous to
the hidden Markov model, with the key
This corresponds to a conventional pixel difference that the hidden state variables are
decimation for block matching in an 8x8-bock. continuous (as opposed to being discrete in the
The motion vector of these sub-blocks is defined hidden Markov model). Additionally, the hidden
as V' = (vx,vy), where v, and v, denote the Markov model can represent an arbitrary
horizontal and vertical components, respectively. distribution for the next value of the state
These two components are assumed independent. variables, in contrast to the Gaussian noise
model that is used for the Kalman filter. There is
The motion vector of an 8x8-block can be a strong duality between the equations of the
predicted (through KF) from the one of the Kalman Filter and those of the hidden Markov
previous 8x8-block according to the time index k model. A review of this and other models is
of the zig-zag order using the state equation: given in Roweis and Ghahramani (1999).
In order to use the Kalman filter to estimate the
V(k+ 1 )=F(k)V(k) +W(k)
internal state of a process given only a sequence
of noisy observations, one must model the
where W(k)is the state noise vector, i.e. the process in accordance with the framework of the
prediction error with covariance matrix Q. The Kalman filter. This means specifying the
state noise components w,, w, are assumed matrices Fk, Hk, Qk, Rk, and sometimes Bk for
independent and Gaussian distributed with each time-step k as described below.
zero-imean and same variance q. The matrix
F(k) is the transition matrix which describes
the dynamic behaviour of the motion vector
from one 8x8-block to the next:
7
matrix at the lower right. The Kalman filter imshow(Im)
model assumes the true state at time k is evolved Imwork = double(Im);
from the state at (k − 1) according to: %extract ball
[cc(i),cr(i),radius,flag] =
Where, extractball(Imwork,Imback,i);%,fig1,fig2,fig3,fi
Fk is the state transition model which is applied g15,i);
to the previous state xk−1; if flag==0
Bk is the control-input model which is applied to continue
the control vector uk; end
wk is the process noise which is assumed to be hold on
drawn from a zero mean multivariate normal for c = -0.9*radius: radius/20 : 0.9*radius
distribution with covariance Qk. r = sqrt(radius^2-c^2);
plot(cc(i)+c,cr(i)+r,'g.')
At time k an observation (or measurement) zk of plot(cc(i)+c,cr(i)-r,'g.')
the true state xk is made according to end
%Slow motion!
where Hk is the observation model which maps pause(0.02)
the true state space into the observed space and end
vk is the observation noise which is assumed to figure
be zero mean Gaussian white noise with plot(cr,'g*')
covariance Rk. hold on
plot(cc,'r*')
The initial state, and the noise vectors at each
step {x0, w1, ..., wk, v1 ... vk} are all assumed to <extractball.m>
be mutually independent.
Many real dynamical systems do not exactly fit % extracts the center (cc,cr) and radius of the
this model; however, because the Kalman filter largest blob
is designed to operate in the presence of noise, function
an approximate fit is often good enough for the [cc,cr,radius,flag]=extractball(Imwork,Imback,in
filter to be very useful. Variations on the Kalman dex)%,fig1,fig2,fig3,fig15,index)
filter described below allow richer and more cc = 0;
sophisticated models. cr = 0;
radius = 0;
flag = 0;
5.0 Code [MR,MC,Dim] = size(Imback);
% subtract background & select pixels with a
big difference
<Detect.m>
fore = zeros(MR,MC); %image
subtracktion
%detect fore = (abs(Imwork(:,:,1)-Imback(:,:,1)) > 10) ..
clear,clc | (abs(Imwork(:,:,2) - Imback(:,:,2)) > 10) ...
% compute the background image | (abs(Imwork(:,:,3) - Imback(:,:,3)) > 10);
Imzero = zeros(240,320,3); % Morphology Operation erode to remove
for i = 1:5 small noise
Im{i} = foremm = bwmorph(fore,'erode',2); %2 time
double(imread(['DATA/',int2str(i),'.jpg'])); % select largest object
Imzero = Im{i}+Imzero; labeled = bwlabel(foremm,4);
end stats = regionprops(labeled,['basic']);%basic
Imback = Imzero/5; mohem nist
[MR,MC,Dim] = size(Imback); [N,W] = size(stats);
% loop over all images if N < 1
for i = 1 : 60 return
% load image end
Im = (imread(['DATA/',int2str(i), '.jpg']));
8
kfinit=0;
% do bubble sort (large to small) on regions in x=zeros(100,4);
case there are more than 1
id = zeros(N); % loop over all images
for i = 1 : N for i = 1 : 60
id(i) = i; % load image
end Im = (imread(['DATA/',int2str(i), '.jpg']));
for i = 1 : N-1 imshow(Im)
for j = i+1 : N imshow(Im)
Imwork = double(Im);
if stats(i).Area < stats(j).Area
tmp = stats(i);
%extract ball
stats(i) = stats(j);
[cc(i),cr(i),radius,flag] =
stats(j) = tmp; extractball(Imwork,Imback,i);
tmp = id(i); if flag==0
id(i) = id(j); continue
id(j) = tmp; end
end hold on
end for c = -1*radius: radius/20 : 1*radius
end r = sqrt(radius^2-c^2);
% make sure that there is at least 1 big region plot(cc(i)+c,cr(i)+r,'g.')
if stats(1).Area < 100 plot(cc(i)+c,cr(i)-r,'g.')
return end
end % Kalman update
selected = (labeled==id(1)); i
% get center of mass and radius of largest if kfinit==0
centroid = stats(1).Centroid; xp = [MC/2,MR/2,0,0]'
radius = sqrt(stats(1).Area/pi); else
cc = centroid(1); xp=A*x(i-1,:)' + Bu
cr = centroid(2); end
flag = 1; kfinit=1;
return PP = A*P*A' + Q
K = PP*H'*inv(H*PP*H'+R)
x(i,:) = (xp + K*([cc(i),cr(i)]' - H*xp))';
<kalman.m> x(i,:)
[cc(i),cr(i)]
clear,clc P = (eye(4)-K*H)*PP
% compute the background image
Imzero = zeros(240,320,3); hold on
for i = 1:5 for c = -1*radius: radius/20 : 1*radius
Im{i} = r = sqrt(radius^2-c^2);
double(imread(['DATA/',int2str(i),'.jpg'])); plot(x(i,1)+c,x(i,2)+r,'r.')
Imzero = Im{i}+Imzero; plot(x(i,1)+c,x(i,2)-r,'r.')
end end
Imback = Imzero/5; pause(0.3)
[MR,MC,Dim] = size(Imback); end
9
diffp = posn - ones(6,1)*mp; computational complexity. Indeed, due to the
Rnew = (diffp'*diffp)/5; basic formulation of the motion, the Kalman
filter equations can be largely simplified and thus
reduced to their scalar form. Subsequently, any
expensive matrix calculation is avoided.
6.0 RESULTS
For comparison purposes, the Full Search
Algorithm (FSA), the Three Step Algorithm 7.0 Conclusion
(TSA), the 16x16-block based Kalman Filter
(16x16-KF) presented in [22] and the proposed The above presented results are encouraging, in
8x8-block based Kalman Filter (8x8-KF) are run the sense that with the appropriate state model
for different classes of video sequences. We use and a priori assumptions close to the real motion
50 frames of the following sequences: ‘Alkistis’, vector behaviour, we are able through Kalman
‘Carphone’, ‘Foreman’ and a sub-sampled filtering to have a greater PSNR than the other
sequence of ‘News’. techniques for any frame of the sequence. It is
evident that a Kalman filter using such simple
It is observed that all the above listed techniques formulation as in this paper is more suitable for
can be qualified as sub-optimal techniques. Even class A image sequences. At this point, there are
the full search algorithm does not give the real few questions I alternatives that may be of
motion. Hence, in any case the results expected interest:
are very close in terms of average PSNR (see -Shall we consider sub-pixel accuracy?
Table 1). -Shall we leave the motion components
As in, the algorithm using the Kalman filtering independency assumption and consider the real
on a 16x16-block basis provides a greater correlation that exists between the displacement
average peak signal to noise ratio than the one in x- and y-direction?
resulting from the conventional three step -Shall we envisage more elaborate state-space
algorithm. As expected the 8x8- block based representation for the motion that will imply
proposed approach results in an even greater implementation of extended Kalman filters and
PSNR better than both the TSA and 16x16-KF. parallel Kalman filters?
For the particular state-space representation Any of the above consideration is feasible.
used, when the real motion corroborate the Regarding the usefulness of implementing such
assumptions made regarding, only translational approaches, this will be a matter of trade-off
motion with very smooth changes, the 8x8-block among the resulting motion estimates, the
based motion estimation using Kalman filter is computational complexity and the real visual
even better than the one resulting from the full quality of the images.
search algorithm, as one can see from the
average PSNR values and the curves in Figure 1. References
The computational complexity of each of
the above stated algorithms is given in Table 2. [1] H. G. Musmann, P. Pirsch and H.-J. Grallert,
The complexity is evaluated in terms of number ‘Advances in picture coding’, Proc. IEEE,
of operations per block (NOPB). The Vol. 73, No. 4, pp. 523-548, 1985.
formulation of the complexity uses N=16 and [2] I. Aksu, F. Jldiz and J. B. Burl, ‘A
p=7, where N defines the size of a NxN-block comparison of the performance of image
and p the maximum displacement within the motion operating on low signal to noise ratio
search area. The full search requires (2p+1)’ images’, Proc. of the 34th Midwest Symposium
search locations and the three step 25. on Circuits and Systems, Vol. 2, pp. 1124-1
The Kalman filter is usually of high 128, NY 1992.
complexity. But for our particular application, [3] A. Murat Tekalp, ‘Digital video processing’,
that uses an intentionally simple state-space Prentice-Hall, 1995.
model for the motion, it is observed from Table 2 [4] Internet resources
that the Kalman filter implementation for
refining the motion estimates resulting from the
TSA, does not significantly increase the
10