OpenCV: Blurring Effect optimization guide as Expected with Custom Kernel Size in Image Processing
Does anyone know how to I'm following best practices but I'm trying to apply a custom Gaussian blur to an image using OpenCV (version 4.5.3), but I'm working with unexpected results that are not matching my expectations. Instead of a smooth blur, the output image appears more pixelated, and sometimes I can see distinct edges in areas that should be blended smoothly. Hereโs what Iโve done so far: I created a custom kernel size of (7, 7) and attempted to use `cv2.GaussianBlur()` as follows: ```python import cv2 import numpy as np # Load the image image = cv2.imread('input.jpg') # Define custom kernel size kernel_size = (7, 7) # Apply Gaussian Blur blurred_image = cv2.GaussianBlur(image, kernel_size, 0) # Save output image cv2.imwrite('blurred_output.jpg', blurred_image) ``` The input image is a high-resolution image (4000x3000 pixels), and I was expecting a smooth blur effect. However, when I inspect the resulting `blurred_output.jpg`, I notice that while some areas are blurred, others are still quite sharp, almost as if the blur is not being applied uniformly. One thing I considered was the nature of the input image itself; it has quite a bit of detail and noise. I also tried adjusting the kernel size to (15, 15) and (21, 21) but the results were similar. Additionally, I tried using `cv2.bilateralFilter()` with parameters: ```python # Apply bilateral filter for better smoothing bilateral_image = cv2.bilateralFilter(image, d=15, sigmaColor=75, sigmaSpace=75) cv2.imwrite('bilateral_output.jpg', bilateral_image) ``` The bilateral filter did give me a better result, but itโs significantly slower and still not quite what I want. I suspect that it might have something to do with the kernel size or the way Iโm applying the Gaussian blur. Has anyone experienced similar issues, or can someone point out what I might be doing wrong? Are there specific parameters I should be tuning for better results? Any help would be greatly appreciated! I'm working in a macOS environment. This is happening in both development and production on Ubuntu 20.04. Any ideas what could be causing this?