Feature Request - Bilateral Filter

Bilateral filtering would be a great feature.

It’s possible. There’s a bilateral filter in the OpenCV toolkit, so I could look at that and see if it’s acceptably fast (it comes with a warning that it’s much slower than their other filters). There are other options - there’s a DFT-based approximation detailed on ipol that appears to converge pretty closely. What’s the use case? Do you just want to apply an edge-aware smoothing function, or do you have something more complex in mind, like using a bilateral filter as part of a HDR exposure blend / tone mapping process for high dynamic range targets like Andromeda or M42?

What the use of such a filter?

Bilateral filter has actually a lot of uses. We have it in G’MIC, and it’s used in many different filters.
What I like with it is:

  • It is good to get anisotropic smoothing (edge-preserving) done fast. There is a trick for a fast implementation that makes it quite efficient in practice (I mean, for an edge-preserving smoothing filter) : https://cs.brown.edu/courses/cs129/2012/lectures/bf_course_Brown_Oct2012.pdf

  • Anisotropic smoothing means it can be used for image denoising.

  • Anisotropic smoothing means it can be also used for image sharpening :slight_smile: (as you can extract high-frequency details easily by computing the difference between the image and its smoothed version, so you can boost those details afterwards).

  • There is also a “guided” version of the bilateral filter that is also very useful, for instance to regularize noise chroma channels from a clean luminance channel.

  • I know it has been also used successfully in the context of HDR/tone mapping : Fast Bilateral Filtering for the Display of High-Dynamic-Range Images

Note that there is a variant of bilateral filtering, named “Guided filtering” (Guided filter - Wikipedia), which is even easier to implement, and has similar properties (even better according to the paper : https://web.archive.org/web/20170323172320/http://www.jiansun.org/papers/GuidedFilter_ECCV10.pdf).
Both approaches give different results, I’d say it’s good to have both :wink:

1 Like

At HogwartsSiril, help will always be given to those who ask for it.

I’ve added a merge request in git that adds the OpenCV bilateral filter implementation. It’s just a basic command and GUI wrapper around cv::bilateralFilter() but it exposes all the arguments that function can take. It appears to struggle with extreme dynamic range (stars bloat a little) but with careful choice of parameters it looks like it can work nicely for noise reduction of a starless image. I still think overall the results are likely to be better from the more advanced noise reduction algorithms in Siril, but cv::bilateralFilter is certainly quick.

The guided filter does look more interesting, especially in the context of chroma noise reduction through edge-preserved smoothing, as Siril’s noise reduction algorithms are tuned for Gaussian white noise or Poisson noise and don’t tend to do well with the lower frequency components of chroma noise. But that will take quite a lot longer to investigate and possibly implement.

2 Likes

My suggestion originally was meant to address edge-aware noise filtering but now I find this discussion very intriguing. It would be great if chromatic noise reduction was included but I am excited to see what evolves.