Skip to content

7 ‐ The Effects of Filtering

Balint Laczko edited this page Feb 4, 2022 · 6 revisions

When working with the motion method, there is an option to filter the video frames after calculating the absolute difference between subsequent frames.

The threshold filter basically "removes" pixels (ie. turns them to black) if their luminosity is under a defined threshold. In our implementation the thresh parameter works in a normalized space: 0 to 1 for 0% and 100% respectively, where 100% means white.

Finding the right threshold value is crucial for accurate motion extraction. Let's see a few examples.

Example 1 | thresh=0

Here is an example of extracting the motion without any threshold. This will result in a result in which much of the background noise will be visible, including traces of keyframes if the video file has been compressed.

source = musicalgestures.MgVideo('/path/to/source/video.avi', starttime=5, endtime=10, skip=0, contrast=100, brightness=20)
motiongrams = source.motiongrams(thresh=0.0)
Vertical motiongram
Horizontal motiongram
Vertical (upper) and horizontal (lower) motiongrams, no threshold filter

Example 2 | thresh=0.02

Adding just a little bit of thresholding (0.02 here) will drastically improve the final result.

Vertical motiongram
Horizontal motiongram
Vertical (upper) and horizontal (lower) motiongrams, 2% threshold filter

Example 3 | thresh=0.1

The standard threshold value (0.1) generally works well for many types of videos.

Vertical motiongram
Horizontal motiongram
Vertical (upper) and horizontal (lower) motiongrams, 10% threshold filter

Example 4 | thresh=0.5

A more extreme value (for example 0.5) will remove quite a lot of the content, but may be useful in some cases with very noisy videos.

Vertical motiongram
Horizontal motiongram
Vertical (upper) and horizontal (lower) motiongrams, 50% threshold filter

As the above examples have shown, choosing the thresholding value is important for the final output result. While it often works to use the default value (0.1), you may improve the result by testing different thresholds.