Python | Bilateral Filtering (original) (raw)

Last Updated : 15 Jun, 2026

Bilateral filtering is an edge-preserving smoothing technique used in image processing to reduce noise while maintaining sharp boundaries in an image. It is widely used in computer vision tasks where preserving structural details is important.

Working Principle

Bilateral filtering smooths an image by computing a weighted average of nearby pixels. The weights are based on two factors:

This ensures that only similar pixels are blended, while edges (high intensity differences) are preserved. The filter behaviour is controlled by:

If \sigma_r is large, the filter behaves similarly to a Gaussian blur.

Implementation

The following example demonstrates the use of OpenCV's bilateral filter for image smoothing. The filter reduces noise while maintaining important edges, and the result is compared with the original image.

**Input Image:

Python `

import cv2

img = cv2.imread('taj.jpg')

bilateral = cv2.bilateralFilter(img, 15, 75, 75)

cv2.imwrite('taj_bilateral.jpg', bilateral)

`

**Output:

Advantages

Limitations