-
Notifications
You must be signed in to change notification settings - Fork 4
/
bg_sub_approxmedian.m
47 lines (40 loc) · 1.13 KB
/
bg_sub_approxmedian.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
xyloObj = VideoReader('4_edge_Sobel.avi');
writerObj1 = VideoWriter('4_Sobel_bg_sub_median');
writerObj2 = VideoWriter('4_Sobel_bg_median');
open(writerObj2);
open(writerObj1);
nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;
considerFrames=nFrames;
n=10;
bg=double(zeros(vidHeight,vidWidth));
bgrnd_img=double(zeros(vidHeight,vidWidth));
for k = 1 : considerFrames
frame = read(xyloObj, k);
frame=double(rgb2gray(frame));
k=k
if(k>n)
for i = 1 : vidHeight
for j = 1 : vidWidth
if( frame(i,j)> bg(i,j) )
bg(i,j)=bg(i,j)+1;
else
bg(i,j)=bg(i,j)-1;
end
end
end
bg=double(bg);
im_sub=uint8(frame - bg);
else
bgrnd_img=bgrnd_img+(frame);
bg= bgrnd_img/k;
im_sub=uint8(bg);
end
%im_sub=uint8(imbinarize(im_sub,0.10)*255); %BEST TILL NOW
writeVideo(writerObj2, uint8(bg));
writeVideo(writerObj1, im_sub);
end
%bgrnd_img=uint8(bgrnd_img);
close(writerObj1);
close(writerObj2);