Median Filter

From emboxit
Jump to: navigation, search

Filter size of 3 The filter size of three is of course the smallest possible filter. It’s possible to find the middle value simply via a few if statements. The code below is based on an algorithm described here. Clearly this is small and fast code. <cpp> uint16_t middle_of_3(uint16_t a, uint16_t b, uint16_t c) {

uint16_t middle;
if ((a <= b) && (a <= c))
{
  middle = (b <= c) ? b : c;
}
else if ((b <= a) && (b <= c))
{
  middle = (a <= c) ? a : c;
}
else
{
  middle = (a <= b) ? a : b;
}
return middle;

} </cpp>