stouputils.data_science.data_processing.image.laplacian module#
- laplacian_image(image: ndarray[Any, dtype[Any]], kernel_size: int = 3, ignore_dtype: bool = False) ndarray[Any, dtype[Any]] [source]#
Apply Laplacian edge detection to an image.
- Parameters:
image (NDArray[Any]) – Image to apply Laplacian edge detection
kernel_size (int) – Size of the kernel (must be odd)
ignore_dtype (bool) – Ignore the dtype check
- Returns:
Image with Laplacian edge detection applied
- Return type:
NDArray[Any]
>>> ## Basic tests >>> image = np.array([[100, 150, 200], [50, 125, 175], [25, 75, 225]]) >>> edges = laplacian_image(image.astype(np.uint8)) >>> edges.shape == image.shape[:2] # Laplacian returns single channel True
>>> rgb = np.random.randint(0, 256, (3,3,3), dtype=np.uint8) >>> edges_rgb = laplacian_image(rgb) >>> edges_rgb.shape == rgb.shape[:2] # Laplacian returns single channel True
>>> ## Test invalid inputs >>> laplacian_image("not an image") Traceback (most recent call last): ... AssertionError: Image must be a numpy array
>>> laplacian_image(image.astype(np.uint8), kernel_size=2) Traceback (most recent call last): ... AssertionError: kernel_size must be odd, got 2