The following piece of code for background subtraction in videos does not work well with a video with vivid/adaptive background.(shows good result for some videos with steady/plain background) I get patched outputs rather than a silhouette. I am working on videos where I need to extract silhouettes of "two humans at a time"(as the foreground) Here is the code and the corresponding output,
fontSize = 14;
obj = VideoReader('sample.avi');
for f=1:frames
I=read(obj,f);
figure(1);
imshow(I);
title('Input Video Sequence');
caption = sprintf('Frame%4d',f);
title(caption, 'FontSize', fontSize);
if f==1
Background=I;
Fg=abs(I-Background);
else
%Background=(1-alpha)* f + alpha * Background;
Fg=abs(I-Background);
end
grayImage = rgb2gray(abs(im2double(Fg))); % Convert to gray level
thresholdLevel = graythresh(grayImage);
binaryImage = im2bw(grayImage,thresholdLevel);
figure(2);
imshow(binaryImage);
drawnow;
pause(0.2)
end
Corresponding Output for a video which contains two humans,
Any Help would be Appreciated! and thanks :)