How to extract foreground image in matlab

I have a .avi file (taken from an Action as a spatio-temporal shape - a classification dataset ) from which I extracted frames in .png format. Now I want to make a foreground definition from these images using Matlab.

I saw one code that uses vision.ForegroundDetector(), but it works for video files.

So please, if someone can give me a definition of the foreground of the code for the images, then I will be very grateful.

This is an example frame:

enter image description here

+4
source share
2 answers

, :

%// read the video:
reader = VideoReader('daria_walk.avi');
vid = {};
while hasFrame(reader)
    vid{end+1} = im2single(readFrame(reader));
end
%// simple background estimation using mean:
bg = mean( cat(4, vid{:}), 4 );
%// estimate foreground as deviation from estimated background:
fIdx = 43; %// do it for frame 43
fg = sum( abs( vid{fIdx} - bg ), 3 ) > 0.25;

:

figure;
subplot(131); imshow( bg ); 
subplot(132); imshow( vid{fIdx} );
subplot(133); imshow( fg );

enter image description here

+6

vision.ForegroundDetector. , .

+1

Source: https://habr.com/ru/post/1617558/


All Articles