필터 지우기
필터 지우기

How to remove a moving object from a video

조회 수: 3 (최근 30일)
divya agarwal
divya agarwal 2012년 10월 19일
댓글: Selva Karna 2017년 9월 13일
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.

채택된 답변

Image Analyst
Image Analyst 2012년 10월 20일
편집: Image Analyst 2012년 10월 20일
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
Selva Karna
Selva Karna 2017년 9월 13일
Dear Image Analyst can you share Code or any morphological operation?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by