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

故事扮演 提交于 2019-11-29 14:49:01

问题


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?


回答1:


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.




回答2:


Fast Median Search - An ANSI C implementation (PDF) is something for C, it's a paper with the title "Fast median search: an ANSI C implementation". The author claims it's O(log(n)), he also provides some code, maybe it'll help you. It's not better than your suggested code, but maybe a look worth.




回答3:


This article describes a method for median filtering of images that runs in O(log r) time per pixel, where r is the filter radius, and works for any data type (be it 8 bit integers or doubles):

Fast Median and Bilateral Filtering




回答4:


I know this question is somewhat old but I also got interested in median filtering. If one is working with signals or images, then there will be a large overlap of data for the processing window. This can be taken advantage of.

I've posted some benchmark code here: 1D moving median filtering in C++

It's template based so it should work with most POD data types.

According to my results std::nth_element has poor performance for a moving median, as it must sort the window of values each time.

However, using a pool of values that is kept sorted, one can perform the median with 3 operation.

  1. Remove oldest value out of the pool (calls std::lower_bound)
  2. Insert new value into pool (calls std::lower_bound)
  3. Store new value in history buffer

The median is now the middle value in the pool.

I hope someone finds this interesting and contributes their ideas!




回答5:


See equations 4 and 5 in the following paper. The complexity is O(N*W) where W is the width of the filter and N is the number of samples.

See Noise Reduction by Vector Median Filtering.



来源:https://stackoverflow.com/questions/10338888/fast-median-filter-in-c-c-for-uint16-2d-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!