Different Filters for Image processing

Raji Lini
7 min readOct 17, 2021

--

Filtering is a standard operation performed on digital images. In image processing, we use 2D filtering techniques. Filters are normally used to remove noises from the image while keeping the image preserved. It’s a technique used for modifying or enhancing the quality of the image. The selection of a filter is based on the nature of the task and the type and behavior of data. Some common filter applications are image smoothing, image sharpening and edge enhancement. The term “convolution” is used for the operation of applying a filter on an image.

source: stackoverflow

Different types

Filters can be applied on digital signals in spatial domain as well as frequency domain. Thus, filters are of two types.

  1. Spatial filters

Spatial Filtering technique is used directly on pixels of an image. Filter mask is usually created in odd size so that it has specific center pixel. This mask is moved on the image such that the center of the mask traverses all image pixels.

2. Frequency filters

This kind of filters are mainly focusing on the frequency of the image instead of the pixel intensity values. It is used for two kinds of operation namely smoothing and sharpening of images.

Also, based on the method applied, filters can be categorized as

  1. Linear filters

Linear filtering is the filtering method where the value of output pixel is linear combinations of the neighboring input pixels. It can be done with convolution operation. For example, mean/average filters or Gaussian filter.

2. Non-Linear filters

Non-linear filter is a filter whose output is not a linear function of its input. Non-linear filtering cannot be done with convolution or Fourier multiplication. Median filter is a simple example of a non-linear filter.

Combinedly, we have filters of types:

  1. Linear spatial filter
  2. Linear frequency filter
  3. Non-linear spatial filter
  4. Non-linear frequency filter

Now, let us discuss about some common filters in image processing and computer vision and their use.

Mean filter

It is linear spatial filter mainly used for smoothing, noise reduction or blurring. It helps reducing the amount of intensity variation between neighboring pixels. The mean filter works by moving through the image pixel by pixel, replacing each value with the average grey level values of neighboring pixels, including itself. There exist two types of mean filters.

a) Average filter

Average filter uses all the coefficients in the kernel matrix same.

Sample Average filter kernel

b) Weighted-average filter

In this, pixels are multiplied by different coefficients. Center pixel is multiplied by a higher value than average filter.

The sample kernel for average filter can be represented as

The main drawback of this filter is that a single pixel with high intensity value in the neighborhood is going to affect the average. Another point is that when the filter convolute with edge values, we get blur edges.

Order statistics filter

This corresponds to non-linear spatial filters. It is based on the ordering of the pixels in the image. It replaces the value of the center pixel with the value determined by a ranking result. These filters are avoiding the kernel and convolution. Edges are better preserved in this type of filtering. Different types of order statistics filters are:

1. Minimum filter

The minimum filter is one of the morphological filters .It is also called as erosion filter. The dark values present in an image are enhanced by the minimum filter. When the minimum filter is applied to a digital image it picks up the minimum value of the neighborhood pixels under the filter window and assigns it to the current pixel. A pixel with the minimum value means the darkest pixel from the window.

When minimum filter is applied, the object boundaries present in an image are extended.

2. Maximum filter

Maximum filter is also called dilation filter. It works opposite to minimum filter. When a maximum filter is applied, the darker objects present in the image are eroded. The maximum filter replaces each pixel value of a digital image with the maximum value(i.e., the value of the brightest pixel) of its neighborhoods.

Applying the maximum filter removes the negative outlier noise present in a digital Image.

3. Median filter

The Median filter is a non-linear filter that is most commonly used as a simple way to reduce noise in an image. Here the pixel value is replaced by the median value of the gray level neighboring pixels. It claims noise reduction over Gaussian and edges are kept relatively sharper.

Median filters are particularly effective in the presence of impulse noise, also called salt-and-pepper noise.

Gaussian filter

It is another linear spatial filter used for smoothing, noise reduction or blurring . Gaussian filtering is more effective at smoothing images. It works similar to human visual perception when processing on images. The kernel coefficients diminish with increasing distance from the kernel’s center. Normally, the kernel matrix are considered symmetric and size of the filter is odd. The values inside the kernel are computed by the Gaussian function, which is as follows:

Two dimensional gaussian function

In gaussian kernel, central pixels have a higher weighting than those on the periphery. The kernel for gaussian filter can be represented as

General form of gaussian kernel (c<a<b)

A 3×3 Gaussian Kernel with standard deviation = 1,is as shown below.

source: geeksforgeeks

This filter is not particularly effective at removing salt and pepper noise.

Derivative filter

The purpose of this linear spatial filter is just the opposite of the smoothing spatial filter. It helps in sharpening the digital image. It’s main focus is the removal of blurring and highlighting the edges. It is based on the first and second order derivative for each group of pixel values considered in x and y directions. Derivative filters provide a quantitative measurement for the rate of change in pixel brightness information present in a digital image.

When a derivative filter is applied to a digital image, the resulting information about brightness change rates can be used to enhance contrast, detect edges and boundaries, and to measure feature orientation. Derivative filters are also called gradient filters.

A 3x3 first derivative filter for the x-direction is

3x3 DFDX filter

Low pass filter

It is a linear frequency domain filter mechanism. Low pass filter removes the high frequency components and keeps low frequency components. It is used for smoothing the image. A low pass filter can be represented as G(x,y)=H(x,y).F(x,y) where F(x,y) is the Fourier Transform of original image and H(x,y) is the Fourier Transform of filtering mask.

High pass filter

High pass filter works in opposite manner of low pass filter. It removes the low frequency components and keeps high frequency components. It is used for sharpening the image. A high pass filter is given by the equation G*(x,y)=1-G(x,y) where G(x,y) is low pass filtering output.

Band pass filter

Band pass filter removes the very low frequency and very high frequency components and keeps the moderate range band of frequencies. Band pass filtering is used to enhance edges by reducing the noise.

Butter-worth filter

It is considered as a variation of ideal low/high pass filters. In image processing, we use butter-worth low pass filters for image smoothing. It removes high frequency noises from the images. The transfer function of Butterworth low pass filter is as follows

where D(x,y) is the Euclidean Distance from any point (x,y) to the origin of the frequency plane.D0 is a positive constant. The filter passes all the frequencies less than D0 value without attenuation. Similarly, Butterworth high pass filters are designed for image sharpening in the frequency domain. The transfer function of Butter-worth high pass filter is

A butter-worth filter is less applied on image since it operates only on frequency domain. The butter-worth filter of higher orders suffer from ringing artifacts.

Some basic filters are explained here. A plenty of filters are designed by applying variations on these. We can dive into this research area and can build new useful and powerful filters for customized applications.

--

--

Raji Lini

By profession an Instructor and now a Research scholar at IIITM-K