Filters in Image Processing Using OpenCV

6+
Computer vision technology is everywhere in a person’s routine. For example, filtered photographs are found everywhere in our social media feed, journals, books, magazine, news articles, etc. Turns out that, image filtering is also a part of us.

What is Image Filtering

Most images captured are affected by noise, that noise can be in various forms like background noise, salt and pepper noise, or intensity disturbance, etc. That noise should be filtered out.  

Filtering is a technique to enhance or to modify the image for its better technical use. For example, you can apply filters to an image to highlight particular features or remove some unwanted features. Image processing with filtering includes image sharpening, image smoothing, and edge-preserving. 

We can consider each location of an image as a pixel value then, by applying filters to images a new and enhanced image is formed by combining the original image and kernel.

Need

An Image consists of a lot of features out of all those we just need to extract only a few and suppress the remaining unwanted ones. To suppress those unwanted, we need a technique to implement an image. For example, the colored image consists of a lot of different colors with different pixel intensities, to remove the difference we apply a technique called Grayscale conversion, the result of this technique consists of only shades of Gray.

Types of Filtering Techniques

The image can be filtered in two ways either in the spatial domain or in the frequency filtration. The two domains of filtering are:

  • Spatial domain
  • Frequency domain

Spatial domain filtering

A technique which is applied directly to pixels of the image. A mask or kernel is created with a particular size, and the mask is moved in a way, that each pixel of the image coincides with the center of the mask.

Classification of Spatial filtering:

  • Smoothing Filters
  • Sharpening Filters

Smoothing Filtering

Colour image smoothing is one of the main parts of pre-processing techniques intended for removing possible noise in the image without losing image information.

The image shown below is taken as input to every image filtering.

Types of Smoothing Filters:

  •  Mean Filter – The mean filter is employed to blur an image to get rid of the noise. This filter calculates the mean of pixel values in a kernel or mask considered. To remove some of the noise, the pixel value of the center element is replaced with mean. We can use the inbuilt function in Opencv to apply this filter.

This is the output image after applying the Mean filter.

  • Gaussian Filter – Gaussian filter is way similar to mean filter but, instead of mean kernel, it uses Gaussian kernel. We should input the height and width (which should be odd and positive) of the kernel along with the standard deviation to the inbuilt kernel function.   

This is the resultant image after applying Gaussian blur

  • Median Filter – Median filter also much similar to the mean filter but, instead of calculating means, we calculate the median of pixel values. And replace the pixel value of the center element with this median value. In the above two filters replacing value is a new value but in the median filter, the median is one of the pixel values.  Median filters help to preserve edges and reduce salt and pepper noise immensely.     

The output of the Median filter

  • Minimum Filter – In this filter, the kernel travels to every pixel, and instead of calculating a new value, the center element pixel value is replaced with a minimum value.
  • Maximum Filter – In this filter, the center element pixel value is replaced with the maximum value within the kernel pixels.
  • Bilateral Filter – Bilateral filtering is highly efficient in preserving edges by removing most of the noise. It replaces the intensity of each pixel with a weighted average of pixel intensity values from neighborhood pixels. This weight is based on the Gaussian distribution. The bilateral filtering technique is at a low pace compared to the remaining others.

Output image after applying Bilateral filter

Sharpening Filtering

The main purpose of the sharpening spatial filter is just the reverse of the smoothing spatial filter. It mainly focuses on highlight the edges and the removal of blurring. A sharpening filter is a derivative filter too. Sharpening filters are dependent on the first and second-order derivatives.   

Frequency domain filtering:

This type of filter concentrates on the frequency of images. These techniques are employed for sharpening and smoothing an image by removing low and high frequencies.    

Frequency domain filters can be further divided into three categories:

  • High-pass filters – High pass filtering technique sharpens the image by passing only high-frequency components and removes or filters low-frequency components.  Function related to high pass frequency domain is:

F(x,y) = 1 – F'(x,y) 

F(x,y) — Fourier transform function of high pass filtering

F’(x,y) — Fourier transform function of low pass filtering

  • Low-pass filters – Low pass filtering technique smoothens the image by passing only low-frequency components and removes the high-frequency components. Function related to low pass frequency domain is:

F(x,y) = 1 – F'(x,y) 

F(x,y) — Fourier transform function of low pass filtering

F’(x,y) — Fourier transform function of high pass filtering

  • Band-pass filter – The bandpass removes the very high frequency and very low-frequency components of the image that means, it keeps the modest range of frequencies. Bandpass filtering is used to preserve edges by removing the noise at the same time.

Application of Filtering in Real-Life

  • Image Processing
  • Tele-communication
  • Audio recording
  • Computer graphics
  • Television
  • Control systems, etc.

Conclusion

Filtration is very crucial in real life and these are some of the filtering techniques that can be applied.

Thanks for reading!

close
6+

You may also like...

1 Response

  1. December 23, 2020

    […] vision problems involve similar low-level patterns like detecting edges, filtering out the noise (Filtering techniques in image processing), etc. We just replace the last layer that makes predictions in our new […]

    0

Leave a Reply

Your email address will not be published. Required fields are marked *

DMCA.com Protection Status