You are on page 1of 10

2D TARGET TRACKING

USING KALMAN FILTER

2006-2007

PROJECT REPORT

SUBMITTED TO THE FACULTY OF


ELECTRONICS AND COMMUNICATION ENGINEERING

NATIONAL INSTITUTE OF TECHNOLOGY, WARANGAL (A.P)


(DEEMED UNIVERSITY)

BACHELOR OF TECHNOLOGY
IN
ELECTRONICS AND COMMUNICATION ENGINEERING

SUBMITTED BY

AMIT KUMAR KARNA (04403)


DEVENDER BUDHWAR (04411)
SAHIL SANDHU (04455)

Under the Guidance of

Dr. T. Kishor Kumar

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING
NATIONAL INSTITUTE OF TECHNOLOGY
(DEEMED UNIVERSITY)
WARANGAL-506004(A.P)

1
Acknowledgements

We would like to express our sincere thanks to our


faculty, Dr. T. Kishor Kumar, Department of Electronics
and Communication Engineering, National Institute of
Technology, Warangal for his constant encouragement,
splendid and gracious guidance throughout our work. He
has been a constant source of inspiration and helped us
in each stage. We express our deep gratitude to him for
such encouragement and kindly cooperation.

Amit Kumar Karna (4403)


Devender Budhwar (4411)
Sahil Sandhu (4455)

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

Abstract Given a macro block in the current frame, the


objective is to determine the block in a reference
It is now quite common in the recursive frame (one of the past for forward motion
approaches for motion estimation, to find estimation or one of the futures for backward
applications of the Kalman filtering motion estimation) in a certain search area that
technique both in time and frequency “best” matches the current macro block
domains. In the block-based approach, very according to a specific criterion. In most coding
few approaches are available of this systems, the “best” match is found using the
technique to refine the estimation of motion mean absolute error (MAE) criterion. There are
vectors resulting from fast algorithms.. This several well known algorithms that perform the
paper proposes an object motion estimation block matching motion estimation, among them
which uses the Kalman filtering technique being the full search algorithm (FSA) that
to improve the motion estimates resulting determines the motion vector of a macro block
from both the three step algorithm and by computing the MAE at each location in the
Kalman application. search area. This is the simplest method, it
provides the best performance, but at a very high
computational cost.

1.0 Introduction To reduce these computational requirements,


several heuristic search strategies have been
developed, as for example the two-dimensional
In the field of motion estimation for video
logarithmic search, the parallel one-dimensional
coding many techniques have been applied. It is
search, etc [3-51. These are often referred to as
now quite common to see the Kalman filtering
fast search algorithms. In fast algorithms the
technique and some of its extensions to be used
procedures applied for motion estimation are of
for the estimation of motion within image
significantly lower complexity, but yield a
sequences.
suboptimal solution in the sense that they may
Particularly in the pixel-recursive approaches,
not avoid the convergence of the MAE cost
which suit very much the Kalman formulation,
function to a local minimum instead of the global
one finds various ways of applying this
one. Lately, some new fast strategies as well as
estimation technique both in the time and
motion estimation have been proposed. But, very
frequency domains. On a very general
few applications are available of Kalman
perspective, we find use of Kalman filter (KF),
filtering for the estimation of motion vectors.
which implies linear state-space representations
and the extended Kalman filter (EKF), which
This paper proposes a motion estimation using
uses the linearised expressions of non-linear
Kalman filtering to improve the motion vector
state- space formulations. Moreover, the parallel
estimates resulting from both the conventional
extended Kalman filter (PEKF) which consists of
three step algorithm (TSA) based Kalman filter
a parallel bank of EKF’s, is often encountered in proposed in Section 2 introduces the state-space
practice. representation for the motion vector. The
In the block-based motion-compensated corresponding Kalman equations are:
prediction approaches, the most common
procedure is the block- matching technique.

4
(optimal Kalman gain)

(updated state estimate)

(updated estimate covariance)


The formula for the updated estimate covariance
above is only valid for the optimal Kalman gain.
Usage of other gain values require a more
complex formula found in the derivations
section.
Invariants
If the model is accurate, and the values for
and accurately reflect the distribution of the
initial state values, then the following invariants
are preserved: all estimates have mean error zero
2.0 The Kalman Filter
The Kalman filter is a recursive estimator. This
means that only the estimated state from the where E[ξ] is the expected value of ξ, and
previous time step and the current measurement covariance matrices accurately reflect the
are needed to compute the estimate for the covariance of estimates
current state. In contrast to batch estimation
techniques, no history of observations and/or
estimates is required. It is unusual in being
purely a time domain filter; most filters (for
The Kalman filter can be regarded as an adaptive
example, a low-pass filter) are formulated in the
low-pass infinite impulse response Digital filter,
frequency domain and then transformed back to
with cut-off frequency depending on the ratio
the time domain for implementation.
between the process- and measurement (or
The state of the filter is represented by two
observation) noise, as well as the estimate
variables:
covariance. Frequency response is, however,
, the estimate of the state at time k; rarely of interest when designing state estimators
, the error covariance matrix (a measure of such as the Kalman Filter, whereas for Digital
the estimated accuracy of the state estimate). Filters, frequency response is usually of primary
concern. For the Kalman Filter, the important
The Kalman filter has two distinct phases: goal is how accurate the filter is, and this is most
Predict and Update. The predict phase uses the often decided based on empirical Monte Carlo
estimate from the previous timestep to produce simulations, where "truth" (the true state) is
an estimate of the current state. In the update known.
phase, measurement information from the In the extended Kalman filter (EKF) the state
current timestep is used to refine this prediction transition and observation models need not be
to arrive at a new, (hopefully) more accurate linear functions of the state but may instead be
estimate. (differentiable) functions.
Predict

(predicted state) The function f can be used to compute the


predicted state from the previous estimate and
(predicted estimate covariance) similarly the function h can be used to compute
Update the predicted measurement from the predicted
state. However, f and h cannot be applied to the
(innovation or measurement residual) covariance directly. Instead a matrix of partial
derivatives (the Jacobian) is computed.
(innovation (or residual) covariance)

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

The measurement set up to time t is

The probability distribution of updated is


proportional to the product of the measurement
Relationship to recursive Bayesian estimation likelihood and the predicted state.

The true state is assumed to be an unobserved


Markov process, and the measurements are the The denominator
observed states of a hidden Markov model.

is a normalization term.
The remaining probability density functions are

Note that the PDF at the previous timestep is


inductively assumed to be the estimated state and
Because of the Markov assumption, the true state covariance. This is justified because, as an
is conditionally independent of all earlier states optimal estimator, the Kalman filter makes best
given the immediately previous state. use of the measurements, therefore the PDF for
given the measurements is the Kalman
Similarly the measurement at the k-th timestep is filter estimate.
dependent only upon the current state and is
conditionally independent of all other states
given the current state. 3.0 State-space representation

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:

It is observed that the measured motion


vectors are actually obtained from the TSA
run on a 16x16-block basis that yields the zig-
zag sequence of four measured motion vectors Fig. Model underlying Kalman filter
Y(k) with same values on the 8x8-block basis. Model underlying the Kalman filter. Circles are
This means that the Kalman filter has four vectors, squares are matrices, and stars represent
measurements instead of one to adjust the Gaussian noise with the associated covariance

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

% Kalman filter initialization % show positions


R=[[0.2845,0.0045]',[0.0045,0.0455]']; figure
H=[[1,0]',[0,1]',[0,0]',[0,0]']; plot(cc,'r*')
Q=0.01*eye(4); hold on
P = 100*eye(4); plot(cr,'g*')
dt=1; %end
A=[[1,0,0,0]',[0,1,0,0]',[dt,0,1,0]',[0,dt,0,1]']; %estimate image noise (R) from stationary ball
g = 6; % pixels^2/time step posn = [cc(55:60)',cr(55:60)'];
Bu = [0,0,0,g]'; mp = mean(posn);

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

You might also like