Filter löschen
Filter löschen

How to remove a moving object from a video

3 Ansichten (letzte 30 Tage)
divya agarwal
divya agarwal am 19 Okt. 2012
Kommentiert: Selva Karna am 13 Sep. 2017
I have written the code given below for separating the object & background of each frame in a video in two separate struct.
obj=VideoReader('butterfly.avi');
a=read(obj,1);
size=size(a);
r=size(1);
c=size(2);
n=obj.NumberOfFrames;
m(1:100)=struct('R',zeros(r,c,'uint8'),'G',zeros(r,c,'uint8'),'B',zeros(r,c,'uint8'));
p(1:100)=struct('R',zeros(r,c,'uint8'),'G',zeros(r,c,'uint8'),'B',zeros(r,c,'uint8'));
for i=1:r
for j=1:c
for k=1:n
u=read(obj,k);
v=read(obj,k+1);
if(abs(u(i,j,1)-v(i,j,1))>0)
m(k).R=u(i,j,1);
else
p(k).R=u(i,j,1);
end
if(abs(u(i,j,2)-v(i,j,2))>0)
m(k).G=u(i,j,2);
else
p(k).G=u(i,j,2);
end
if(abs(u(i,j,3)-v(i,j,3))>0)
m(k).B=u(i,j,3);
else
p(k).B=u(i,j,3);
end
end
end
end
my idea is to make two separate matrix for each frame one matrix will contain the object and other will contain he background .Then I will replace the zeros in the matrix containing only background with background colour,so that I get a video with object removed. But when I run this code in MATLAB it gets busy for many hours.So please suggest me the way with which I should proceed.Please tell me the problem with my code.

Akzeptierte Antwort

Image Analyst
Image Analyst am 20 Okt. 2012
Bearbeitet: Image Analyst am 20 Okt. 2012
I think you'll be interested in this web site: http://www.mee.tcd.ie/~sigmedia/Research/RigRemoval
Vectorize the code. No need to have loops over rows and columns. Just subtract the images.
A lot of people use Gaussian Mixed Models to get background video, but one easy way that works in some situations where the camera is not moving is to just take the mode of the frames. Basically the most common pixel value will be the background pixel value,kind of by definition of what the background it.
  1 Kommentar
Selva Karna
Selva Karna am 13 Sep. 2017
Dear Image Analyst can you share Code or any morphological operation?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by