Fore Ground Extraction and Back ground subtraction from video in Matlab
Gait recognition project Dataset |
As i'm currently working on biometric gait recognition project so to complete that project i have to background subtraction to extract foreground from video.
i'm using CASIA data set videos for my experiments.
So background subtraction is the first thing to do in my project so when we have extracted human structure from video we easily perform our algorithms on it to identify its gait.
Matlab code for background subtraction using frame difference:
clc; % clear command window
clear all; % clear work space
% Reading video from computer directory
videoObject = VideoReader('001-bg-01-090.avi');
% Determine how many frames there are.
numberOfFrames = videoObject.NumberOfFrames;
% Loop through all frames
for frame = 1 : numberOfFrames
% Extract the frame from the movie structure.
img1 = read(videoObject, frame);
img2 = read(videoObject, frame+10);
% In above we take two frame to subtract them from each other
% Subtract frames from each other
img3 = imsubtract(img1,img2);
% Convert the subtracted result to rgb
img4 = rgb2gray(img3);
% Apply sobel edge detection on rbg frame
img5 = edge(img4,'Sobel');
% Use morphological approach to fill holes
d = bwmorph(ege,'remove',1);
e = imfill(d,'holes');
% And now save them one by one in hard-disk
outputFolder = '\newdataset\chknew1';
FileName = sprintf('img%.2d.png', frame);
outputFileName = fullfile(outputFolder, FileName);
imwrite(e, outputFileName, 'png');
end
Result gave us images in 'png' format like in below
Post a Comment