fourMs / MGT-python

Musical Gestures Toolbox for Python
https://www.uio.no/ritmo/english/research/labs/fourms/downloads/software/musicalgesturestoolbox/mgt-python/index.html
GNU General Public License v3.0
52 stars 11 forks source link

Background subtraction #270

Closed alexarje closed 1 year ago

alexarje commented 1 year ago

It would be good to have a simple way of doing background subtraction based on on a static image. That is, a function that would read a video file + an image, and subtract the image for each video frame. The image could be a still from a video recording (e.g. in the beginning) or made as an average image of a short video recording. The main point would be to get a "clean" foreground video.

joachimpoutaraud commented 1 year ago

I have started to look for a simple way of doing background subtraction based on static image and ended up using ffmpeg. Here are the resuls I managed to obtain so far, with the following foreground and background images.

Foreground fore Background bg

After differentiatng frames and applying curves and equilisation filtering, I propose to subtract the background according to 4 different thresholds (i.e extra_soft', 'soft', 'medium', 'hard'). I could nevertheless add more threshold flexibility to the user. Here are the results.

Extra soft result1 Soft result Medium result2 Hard result3

On the other hand, I also tried this algorithm on the average image of a video recording and it works quite well too!

Background pianist_average Foreground result

I will now work on implementing it in the MGT

alexarje commented 1 year ago

Great, looks nice. Very good to have this in the toolbox!

joachimpoutaraud commented 1 year ago

I have finish to implement a new subtract function in the toolbox for doing background subtraction based on on a static image. More information on how to use it can be found in the wiki documentation.