If you have ever worked on a Computer Vision project, you might know that using augmentations to diversify the dataset is the best practice. On this page, we will:
Let's jump in.
To define the term, Blur is a data augmentation technique that helps researchers to blur images with a certain likelihood.
Blur filter is derived from convolution, a popular image-processing technique that changes the pixel's value with regard to the values of its surrounding pixels.
At the heart of convolution operation are Kernels, 1D or 2D grids of numbers that show how the neighboring pixels affect the given pixel's transformed value.
To count the value of a transformed pixel:
The simplest Kernel is the identity Kernel. It is named so since the only value it contains is 1, and applying it does not change the image.
As you can see below, to transform a given pixel, we multiply its value by 1 and all the surrounding pixel values by 0. The sum of the products will result in the initial pixel value (0.5 x 1 = 0.5).
The output of the convolution can vary depending on the Kernel values.
For example, a matrix below is a Sharpen Kernel that sharpens the input image.
To blur an image, we can use a 2D Kernel or box blur Kernel. It results in the average value of the neighboring pixels, decreasing the value of the transformed pixel.
In the example below, the sum of the Kernel values is 1, and each Kernel value is equal to 1/9:
Besides the Kernel values, we can also change the size of the Kernel matrix itself:
You can adjust the intensity of the Blur augmentation by setting the Blur limit parameters.
Hello, thank you for using the code provided by Hasty. Please note that some code blocks might not be 100% complete and ready to be run as is. This is done intentionally as we focus on implementing only the most challenging parts that might be tough to pick up from scratch. View our code block as a LEGO block - you can’t use it as a standalone solution, but you can take it and add to your system to complement it. If you have questions about using the tool, please get in touch with us to get direct help from the Hasty team.
import albumentations as albu
from PIL import Image
import numpy as np
transform =albu.Blur(blur_limit=3, p=0.5)
image = np.array(Image.open('/some/image/file/path'))
image = transform(image=image)['image']
# Now the image is blurred and ready to be accepted by the model
Hasty is a unified agile ML platform for your entire Vision AI pipeline — with minimal integration effort for you.
Start for free Check out our services