Gaussian Blur Image Processing Function

  • Share this:

Code introduction


This function reads an image from a specified path and applies a Gaussian blur filter to it. Gaussian blur can reduce noise and details in the image.


Technology Stack : opencv-python, numpy

Code Type : Image processing

Code Difficulty : Intermediate


                
                    
import cv2
import numpy as np

def blur_image(image_path, kernel_size=(5, 5)):
    # Load the image using OpenCV
    image = cv2.imread(image_path)
    
    # Check if image is loaded properly
    if image is None:
        raise ValueError("Image not found or path is incorrect")
    
    # Apply Gaussian Blur to the image
    blurred_image = cv2.GaussianBlur(image, kernel_size, 0)
    
    return blurred_image