Can somebody please help me detect an object using Principal Component Analysis and track its motion simultaneously using and comparing the performances of recursive Bayesian estimators Kalman and Particle filter?

1 view (last 30 days)
I'm unable to generate a running code which can detect and track the motion using PCA and Kalman and Particle respectively.
  5 Comments
AJ von Alt
AJ von Alt on 20 Jan 2014
Edited: AJ von Alt on 20 Jan 2014
Please edit your submission to use the code style option to make your code more readable.
Some thoughts:
The error you listed happens when you call a function without the necessary number of arguments.
Functions and variables cannot share a name in MATLAB. You should either rename your function i_sub, save the .m file under the new name, and delete i_sub.m or change the name of the variable i_sub.
Yashsavi
Yashsavi on 22 Jan 2014
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function[x,y,ibw]=isub(i_aft,i_bef)
%Takes two images from two frames ,subtracts them and detect the position
%of object by threshholding and calculating centroid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[x,y,ibw]=isub(i_aft,i_bef)
%subtract image
i_sub=i_bef-i_aft;
%convert to binary
igray=rgb2gray(i_sub);
level=graythresh(i_sub);
ibw=im2bw(i_sub,level);
%compute centre of gravity
ibw = imfill(ibw,'holes');
L=bwlabel(ibw);
stats=regionprops(L,'Area','Centroid');
ar=[stats.Area];
s=[stats.Centroid];
armax=max(ar);
mx=max(max(L));
for i=1:mx
if stats(i).Area==armax
centroid=stats(i).Centroid;
end
end
x=centroid(1);
y=centroid(2);
x=round(x);
y=round(y);
[m n r]=size(i_aft);
for k=1:m
for l= 1:n
if (k==y && l==x)
for t= 0:4
i_aft(k-t,l-t,:)= 0;
i_aft(k-t,l-t,3)=255;
i_aft(k-t,l+t,:)= 0;
i_aft(k-t,l+t,3)=255;
end
end
end
end
imshow(i_aft);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Take images in real time and send to Function isub for processing
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
vid=videoinput('winvideo',1);
triggerconfig(vid,'manual');
set(vid,'FramesPerTrigger',1);
set(vid,'TriggerRepeat',Inf);
start(vid);
while(1)
for j=1:3
trigger(vid);
im=getdata(vid,1);
if j==1
i_bef=im;
end
if j==3
i_aft=im;
end
end
[x,y,u]=isub(i_aft,i_bef);
end

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!