フィルターのクリア

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