Mean Filter in Image Processing

Sandaminimadhushika
3 min readSep 21, 2021

Noise removal technique

When an image is acquired by a web camera or other imaging system, normally the vision system for which it is intended is unable to use it directly. The image may be corrupted by random variations in intensity, variations in illumination, poor contrast or noise that must be handle with in the early stages of vision processing.

Introduction

Therefore, mean filter is one of the techniques which is used to reduce noise of the images.

This is a local averaging operation and it is a one of the simplest linear filter. The value of each pixel is replaced by the average of all the values in the local neighborhood. Let f(i,j) is a noisy image then the smoothed image g(x,y) can be obtained by,

Where S is a neighborhood of (x,y) and n is the number of pixels in S.

eg :- 3x3 mean filtering,

Programming

Now, it is time to write some code. let us come down to programming.

first you have to take a image as input. Here we use gray image,

Then we can define the kernel size. we can use 3x3, 5x5 kernels etc. When the kernel size is increased, noise is more smoothed. Let’s take the kernel size as a command line argument,

Let’s apply the mean filter to the salt and paper noisy gray image.

Pros and Cons

Then you can simply display the both noisy and filtered images by creating windows. Mean filtering is a simple, intuitive and easy to implement method of smoothing images. It is often used to reduce noise in images. Also it is reducing the amount of intensity variation between one pixel and the next.

But there are some problems of this mean filter,

A single pixel with a very uncommon value(outlier) can significantly affect the mean value of all the pixels in its neighborhood.

Input image, output image with 3x3 kernel and output image with 5x5 kernel are shown bellow.

noisy & filtered images.

That’s all for this article. Thank you for reading!!

--

--