stouputils.data_science.data_processing.image.blur module#

blur_image(image: ndarray[Any, dtype[Any]], blur_strength: float, ignore_dtype: bool = False) ndarray[Any, dtype[Any]][source]#

Apply Gaussian blur to an image.

Parameters:
  • image (NDArray[Any]) – Image to blur

  • blur_strength (float) – Strength of the blur

  • ignore_dtype (bool) – Ignore the dtype check

Returns:

Blurred image

Return type:

NDArray[Any]

>>> ## Basic tests
>>> image = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> blurred = blur_image(image.astype(np.uint8), 1.5)
>>> blurred.shape == image.shape
True
>>> img = np.zeros((5,5), dtype=np.uint8)
>>> img[2,2] = 255  # Single bright pixel
>>> blurred = blur_image(img, 1.0)
>>> bool(blurred[2,2] < 255)  # Center should be blurred
True
>>> rgb = np.full((3,3,3), 128, dtype=np.uint8)
>>> blurred_rgb = blur_image(rgb, 1.0)
>>> blurred_rgb.shape == (3,3,3)
True
>>> ## Test invalid inputs
>>> blur_image("not an image", 1.5)
Traceback (most recent call last):
        ...
AssertionError: Image must be a numpy array
>>> blur_image(image.astype(np.uint8), "1.5")
Traceback (most recent call last):
        ...
AssertionError: blur_strength must be a number, got <class 'str'>