0
$\begingroup$

I was wondering about the implementation of the Median Filter in opencv because I am suffering form its slowness. So, I intend to implement another one on my own but first I want to make sure about the used algorithm in opencv. Many thanks

$\endgroup$
1
$\begingroup$

OpenCV is "Open source computer vision". So all source code is open. See - http://code.opencv.org/projects/opencv/wiki#Development. Download sources from git, find code for median filter. Modify it. If you code will be better - contribute to OpenCV.

$\endgroup$
1
$\begingroup$

I don't know about opencv's implementation, but a median filter can indeed be very slow because for every windows you have to sort your data in order to find the median. However there is a recursive implementation of the median filter, which is much more quick. It is very simple to build.

The basic idea is to recursively build the data's histogram that will allow you to very quickly get the median without sorting : For the first window, fully build the histogram, then, shift your windows by one step (or more, it depends on you), remove the last value from the previous window and add the new one, you updated your histogram with only 2 operations. Then you have to find the median within the histogram, this is recursively feasible but I don't remember the exact implementation (it is a bit more tricky), however simply checking the histogram's cumulative sum, while brutal, will give you the median quickly (worst case scenario is N summation, with N your window's size).

$\endgroup$
  • $\begingroup$ Thank you @antoine. It seems interesting idea and I am going try it but I am afraid that opencv may use the same idea so I want to make sure first that the algorithm I am going to implement is not the same of opencv. $\endgroup$ – Humam Helfawi Apr 24 '15 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.