Noise filtering in Digital Image Processing
Published: 2023-07-16 08:18:32

---
title: Noise filtering in Digital Image Processing
published: true
date: 2018-09-02 21:11:57 UTC
tags: 
canonical_url: https://theuigirl.hashnode.dev/noise-filtering-in-digital-image-processing-d12b5266847c
---

#### IMAGE TECHNOLOGY

#### Noise is always presents in digital images during image acquisition, coding, transmission, and processing steps.

Hello People. In our last article named [Noise in Digital Image Processing](https://medium.com/image-vision/noise-in-digital-image-processing-55357c9fab71) we had promised to get back to you with another article on filtering techniques and filters. So here we are with yet another article of our series Image Vision on Noise Filtering.

Noise is always presents in digital images during image acquisition, coding, transmission, and processing steps. It is very difficult to remove noise from the digital images without the prior knowledge of filtering techniques. In this article, a brief overview of various noise filtering techniques. These filters can be selected by analysis of the noise behaviour. In this way, a complete and quantitative analysis of noise and their best suited filters will be presented over here.

Filtering image data is a standard process used in almost every image processing system. Filters are used for this purpose. They remove noise from images by preserving the details of the same. The choice of filter depends on the filter behaviour and type of data.

### Filtering Techniques:

We all know that, noise is abrupt change in pixel values in an image. So when it comes to filtering of images, the first intuition that comes is to replace the value of each pixel with average of pixel around it. This process smooths the image. For this we consider two assumptions.

#### **Assumption:**

1. The true value of pixels are similar to true value of pixels nearby
2. The noise is added to each pixel independently.

Lets first consider 1-dimensional function before going into 2-dimensional image.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558399953/9371f683-4bcb-4666-8fb2-5b585e1cf3d7.png)

In the above image of original function(fig-1), if we will consider each circle as pixel values, then the smoothed function(fig-2) is the result of averaging the side by pixel values of each pixel.

#### 1. Filtering with weighted moving average uniform weight:

Instead of just thinking about averaging the local pixel, which is resulting in some loss of data, we consider a set of local pixel and assign them as uniform weights. Here we assume that noise is added to each pixel independently. According to this noise amount, we assign weights to different pixels.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558402467/2309925e-7100-40de-aad2-6328d84b25a3.png)

#### 2. Filtering with weighted moving average non-uniform weight

Previously we took the assumption that the true value of pixels are similar to true value of pixels nearby. But it is not always true. So for higher accuracy we assign the nearby pixels with greater weight then the pixels that are far away. This smooths the image and preserves the image information with less amount of data loss.

#### 3. Weighted moving average in 2-dimensional image

Thinking of image as a 2-dimensional matrix, we slide a small window( the red square in fig. 5) over the whole image to replace each pixel with the average of nearby pixels. This small window is otherwise known as **mask or kernel.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558404274/37d00115-65d2-4345-befc-d83e1ae81f52.png)

The process used in filtering with uniform weights is also called correlation or **correlation filtering.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558405705/47c517ef-27dd-45ca-8999-d5a975965bd8.png)

Fig.7 Correlation function for uniform weights. src: Udacity

In correlation filtering with non-uniform weight, an function is used as non-uniform weights which is also called **mask or kernel** (function of the pixel values of the small sliding window) **.** The process used in it is called **cross-correlation.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558407802/91d1f46e-1eb2-48c7-b321-eb884597a84e.png)

Fig.8 Correlation function for non-uniform weights .src: Udacity

### Types of Image noise filters:

There are different types of image noise filters. They can typically be divided into 2 types.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558410192/44ef444f-4fb9-4b34-a791-1550c4490d09.png)

Fig.9 Classification of Filters

Though there are many types of filters, for this article we will consider 4 filters which are mostly used in image processing.

#### 1. Gaussian Filter:

In **image processing** , a **Gaussian** blur (also known as **Gaussian** smoothing) is the result of blurring an **image** by a **Gaussian** function (named after mathematician and scientist Carl Friedrich **Gauss** ). It is a widely used effect in graphics software, typically to reduce **image** noise and reduce detail.

#### 1.1 Implementation of Gaussian Filter with OpenCV and Python:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558412751/49484fa8-858b-466e-8a83-430052538850.png)

(Filtering Gaussian Noise)

#### 2. Mean Filter:

Mean filter is a simple sliding window that replace the center value with the average of all pixel values in the window. The window or kernel is usually a square but it can be of any shape.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558416051/c0f951a5-c214-4d06-8218-cc364fb43e5a.png)

Fig.10 Calculating Mean by sliding window

#### 2.1 Implementation of Mean Filter with OpenCV ans Python:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558417628/52c66fef-8e00-4a3e-b6c0-9e77f7c352a4.png)

(Filtering Poisson Noise)

#### 3. Median Filter:

Mean filter is a simple sliding window that replace the center value with the Median of all pixel values in the window. The window or kernel is usually a square but it can be of any shape.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558419952/97c9d150-3f6a-4a01-8fc4-8546f3092e92.png)

Fig.11 Calculating Median by sliding window

#### 3.1 Implementation of Median Filter with OpenCV and Python:

![](https://cdn-images-1.medium.com/max/800/1*v3T5s6mg5MTLLOi3Queq6Q.png)

(Filtering Salt and Pepper noise)

#### 4. Bilateral Filter

Bilateral filter uses Gaussian Filter but it has one more multiplicative component which is a function of pixel intensity difference. It ensures that only pixel intensity similar to that of the central pixel is included in computing the blurred intensity value. This filter preserves edges.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558424169/7ac422de-87b6-423e-9dc8-c857e263843b.png)

![](https://cdn-images-1.medium.com/max/800/1*lpkqwhDxCxrdyWaFW40V6Q.png)

### Analysis of best suited filters for noises:

From the implementation of both noise and filters, we analysed best suited filters for different image noises.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688558429419/c97fe62f-a67b-4b56-8769-632431d3492a.png)

With this we conclude this article on noise filtering in image processing. To know more about noise please refer [this](https://medium.com/image-vision/noise-in-digital-image-processing-55357c9fab71). For more updates on image processing stay tuned with us and let us know your queries with your comments. Happy Coding!

> _Let us your thoughts about the article in the comment section below and if you want to connect with me, here I am ->_ [_Twitter_](https://twitter.com/anishaswain) _or_ [_Linkedin_](https://www.linkedin.com/in/anisha1234) _or_ [_Instagram_](https://www.instagram.com/anisha_swain_/)