I know this question is somewhat old, but I was also interested in median filtering. If you work with signals or images, then for the processing window there will be a lot of data overlap. It can be used.
I posted a few benchmarks here: 1D moving median filtering in C ++
This template is based on the fact that it should work with most POD data types.
According to my results, std::nth_element
has poor performance for a moving median, since it must sort the value window every time.
However, using a pool of values ββthat are sorted, you can perform a median with 3 operations.
- Delete the old value from the pool (calls to std :: lower_bound)
- Paste the new value into the pool (calls to std :: lower_bound)
- Save new value in history buffer
The median is now the average value in the pool.
I hope someone finds this interesting and brings in their ideas!
source share