Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Median Filter Super efficient implementation

I am looking for a Ansi C implementation of a fast/efficient median filter. Any pointers?

So far, I have found the following implementation, which is good but I am curious on faster ones. I only need for 1 dimension.

like image 245
user4749 Avatar asked Jul 14 '12 09:07

user4749


1 Answers

I needed to extract a signal from very noisy CPU consumption data. Here's the Jeff McClintock median filter...

Initialize the average and median to zero, then for each sample 'inch' the median toward the input sample by a small increment. Eventually it will settle at a point where about 50% of the input samples are greater, and 50% are less than the median. The size of the increment should be proportional to the actual median. Since we don't know the actual median, I use the average as an rough estimate. The step size is calculated as 0.01 times the estimate. Smaller step sizes are more accurate, but take longer to settle.

float median = 0.0f;
float average = 0.0f;

// for each sample
{
    average += ( abs(sample) - average ) * 0.1f; // rough running average magnitude.
    median += _copysign( average * 0.01, sample - median );
}

enter image description here

like image 190
Jeff McClintock Avatar answered Oct 09 '22 22:10

Jeff McClintock