Making Images Blurry

Learn how to make images blurry.

We'll cover the following

We might have used different features in our cameras or photo editing tools, such as making the images blurry. These features make our images more suitable for different contexts.

Making an image blurry

We have to use the GaussianBlur() method to make an image blurry. We need to give four parameters to this function:

  • The original image
  • The blurred image
  • Kernel size
  • SigmaX
cv::Size kernelSize = Size(7,7)
int sigmaX = 0
cv::GaussianBlur(img, blurredImg, kernelSize, sigmaX); 

Note: We need to read the image as img using the imread function and declare header files and namespaces.

In the code above, sigmaX represents the kernel’s standard deviation in the x-direction.

Kernel size

Here, the kernelSize is the size of the window where the blur is applied. It should be in odd numbers. This will make the previous layer’s pixels similar to the output pixel. If we use even numbers, we might suffer from aliasing errors. Increasing the number will increase the blurriness of the image.

Let’s try blurring the image with a different kernelSize and check out the differences.

Get hands-on with 1200+ tech skills courses.