Lulumoy Studio

Math guide

Bilateral filter

Smooths uniform areas without blurring edges: each neighbour is weighted by its distance and by how similar its value is to the centre pixel.

I′(p)=1Wp∑q∈S(p)Gσs(‖p−q‖)·Gσc(|I(p)−I(q)|)·I(q)
S(p) is the disc of diameter d centred at p and Wp is the sum of the weights, for normalisation.
Gσ(t)=e−t22σ2
In colour images, |I(p) − I(q)| is the sum of the absolute differences of the three channels.

Parameters

ParameterMeaning
Neighbourhood diameterd, neighbourhood diameter in pixels. Large values (above 9) are slow.
Sigma colourσc: intensity difference beyond which two pixels "do not look alike". Large = behaves like a Gaussian.
Sigma spaceσs: spatial reach of the average, in pixels.

References

  1. OpenCV 4.x documentation — Image Filtering (GaussianBlur, blur, medianBlur, bilateralFilter, morphologyEx). docs.opencv.org/4.x/d4/d86/group__imgproc__filter.html
  2. C. Tomasi, R. Manduchi. "Bilateral filtering for gray and color images." Proceedings of the Sixth International Conference on Computer Vision (ICCV), pp. 839–846, 1998.