Search code examples
pythonopencvopenclscikit-image

Is there any existing library for median filtering with kernel size greater then 5 using OpenCL acceleration in python?


Thank you in advance for answering.

I tried a lot of google searching, I saw scipy.sgnal.medfilt2, skimage.filters.median but none of these support OpenCL.

I also saw: https://wiki.tiker.net/PyOpenCL/Examples/MedianFilter?fbclid=IwAR3tnqNEnZ8oVJUWplxkz33Km3aj3uYVbnQQQBsGjLlIjyCxWIijbxaNuGQ

But this code is hardcoded for kernel size: 3.

OpenCV has UMat, the transparent API but it is again limited to kernel size 5.

If you know any library which can do median filtering with kernel size in the order of ~51 using openCL in python, that would be great.

If there isn't one, I am sure, I am not the first person with the need of median filter with a bigger kernel, I very humbly ask Why the community hasn't solved it yet? Is there any technical challenge which I am not aware of? Please educate me.

Thank you again for looking into this.

Regards

HM


Solution

  • Have you tried cv::medianBlur (the 8-bit CPU version) yet? It's moving histogram implementation makes it's complexity O(1) with respect to block radius, thus it is very hard to beat at larger radii no matter how many cores you have. The OpenCL version on the other hand, which is embarrassingly parallel, uses sorting network for the median. Unfortunately such algorithm becomes inpractical quickly as the number of comparison operations required grows very fast.