Bilateral filter
We previously described how the Median filter is poor at performance and bilateral filter is a good supplement to it, to understand why we must look at how the filter works.
The bilateral function takes in a sigma
this describes the intensity of the smoothing similar to Gaussian Blur and the kernel size. We then loop through each pixel, and we will subtract each of its neighbours with the current pixel, we will multiply this with a "weight" and set the current pixel to the mean of the value. That is a bit convoluted (ha!) but let's see the implementation.
Implementation
The Bilateral filter is implemented at src/smoothing/bilateral.c
It's pretty apparent what we are doing here. Let's check the actual bilateral computation
So let's break down what's going on here
We loop through the neighbours of the
centerValue
We then extract the difference of centre value and the current neighbour
From the difference we extract a
rangeWeight
this will define how "sharp" our smoothing istotalWeightedSum
is the sum of product of weight and current neighbourtotalSum
is just the sum of the weightsWe divide the above values and return it. This division is done to "normalise" the image so that it maintains the initial brightness or photometric symmetry, a fancier way to say that an image shares properties with its previous state.
From this we achieve the following result
Result
The performance of this algorithm is a lot better than the one previously discussed.
Last updated