Fast Median Filter in C / C++ for `UINT16` 2D Array

user1359341 picture user1359341 · Apr 26, 2012 · Viewed 26.6k times · Source

Does anyone know a fast median filter algorithm for 16-bit (unsigned short) arrays in c++?

http://nomis80.org/ctmf.html

This one seems quite promising, but it only seems to work with byte arrays. Does anyone know either how to modify it to work with shorts or an alternative algorithm?

Answer

Mark Ransom picture Mark Ransom · Apr 26, 2012

The technique in the paper relies on creating a histogram with 256 bins for an 8 bit pixel channel. Converting to 16 bits per channel would require a histogram with 65536 bins, and a histogram is required for each column of the image. Inflating the memory requirements by 256 makes this a less efficient algorithm overall, but still probably doable with today's hardware.

Using their proposed optimization of breaking the histogram into coarse and fine sections should further reduce the runtime hit to only 16x.

For small radius values I think you'll find traditional methods of median filtering will be more performant.