neuroinformatics-unit / movement

Python tools for analysing body movements across space and time
http://movement.neuroinformatics.dev
BSD 3-Clause "New" or "Revised" License
104 stars 8 forks source link

Smooth trajectories using a median filter #55

Closed niksirbi closed 5 months ago

niksirbi commented 1 year ago

DeepLabCut has some support for smoothing/filtering pose tracks, in the form of the filterpredictions() function in the filtering.py module.

They offer three options:

We should also offer several filtering options eventually, but the median filter is probably the easiest to start with.

Maybe a first step would be to create a filtering.py/smoothing.py module and add a single median filter function. That function should:

niksirbi commented 1 year ago

Primer on mean/median filtering for timeseries data.

niksirbi commented 1 year ago

In xarray, this could be as simple as doing:

da.rolling(time=5).median()

See rolling-window-operations.

If we want to be fancy, we can set the timepoints below a specified confidence threshold to NaN, before applying the median filter.