Image Blurring techniques:
Image blurring techniques is used for the smoothing of an image. These techniques are used to make the image less sharp and less edgy, so the canny edge detector doesn’t detect every possible small edge in an image. Other than that, it is also used to blur the inappropriate images. For example, we have trained a classifier which classifies the inappropriate images, and we want to that whenever the part in an image came it get blurred automatically so after getting the coordinates of that image, we blurred that part.
This technique is also used to make the image simply because the pixel values are fused into each other and the sharpness of an image is reduced. There are many types of blurring techniques in OpenCV we will see all of them one by one:
This technique is used along with the kernel. The kernel window is then iterated all over the image. It takes all the pixel values within a kernel window and replaces the value with the average of all values. This technique normalizes the image and makes it blur. To apply this filter following code should be followed:
The output that is generated as a result is as follows:
Now we can see clearly that the image is blurry. So, this is the first method to make the image blurry.
In this approach, we do not use a standard kernel with equal filter coefficient. Instead, we use the Gaussian Kernel. In the Gaussian kernel, we should specify the width and height of the kernel. It is to be noted that the kernel width and height should be more than 0 and should be an odd number. The 3rd parameter it took is standard deviation that means to what extent the pixel value can deviate along with X and Y axis. If only the value of X is given, the system will take equal to Y. The following code is used to blur an image with the help of Gaussian blur
In the above code, we have increased the size of the kernel. It is important to write the kernel width and height in odd otherwise system will generate the following error:
The error is generated when we changed the value of kernel to (14,14). It says that there is an error while creating the kernel because the width and height’s modulus with 2 must generate the value of 1
When we run the above-given code following image is generated:
As we have increased the value of the kernel, we can see clearly that the image is more blur than the previous one.
Median Filtering Technique:
In this technique, a kernel is used too. The kernel iterates over the image and then the central pixel is then converted into the median value of all pixels. This is highly important when removing the small particles. It can reduce the maximum number of noises from the image without affecting the actual image itself. The salt and pepper noise can be reduced to a great extent with the help of this filter. Just we saw in the case of open filter we reduce the small particles.
Similarly, we will remove those particles with the help of the median filter. It is to be noted in case of averaging and the Gaussian filter the median value is not the actual value of that pixels; however in a median filter, the central pixel is from those group of pixels. This reduces the noise and similar to the case of Gaussian filter the kernel size should be odd and should be positive.
We are going to apply this filter on the following image:
In this image, we can see there are lots of noise. These small particles make noise in an image and so to remove this noise following code is to be run on the image:
We have read an image, and after reading the image, we have applied median blur on it with the kernel size 5, 5. So after running this code following output is generated:
In Figure 4 we can see more than 90% of the noise is removed from the image.
Now the question arises why we use this? So, the answer is when we are performing some task on image these small particles can be detected as the actual object and can cause an obstruction in recognizing the image. So, it is necessary to remove the noise. Another essential reason is supposed you have to create a dataset for classifying an image and you have the images which were taken with the lousy camera so to make the dataset look clean we have to remove the noise before feeding into a machine learning algorithm.
Bilateral Blurring Technique:
In all the previous filtering techniques we have that the edges are not maintained that match the image dilates. However, with the help of bilateral technique, the edges can be preserved, and the other small objects can be blurred. The bilateral method is slower than the other blurring technique because it took more computation than the other.
The code of bilateral blur is as follows:
When to use?
This technique is used when you have to blur the pattern within the actual object suppose we have an image of wood in which small pattern can be seen. So, to remove those patterns without changing the edges of that wood, we will use a bilateral filter to filter out those patterns.