Apply disk blur to an image using FFT convolution. Args: image (np.ndarray): Input image, can be grayscale or color. radius (int): Blur radius (in pixels). Returns: np.ndarray: Blurred image.
(image: np.ndarray, radius: int)
| 327 | |
| 328 | |
| 329 | def disk_blur(image: np.ndarray, radius: int) -> np.ndarray: |
| 330 | """ |
| 331 | Apply disk blur to an image using FFT convolution. |
| 332 | |
| 333 | Args: |
| 334 | image (np.ndarray): Input image, can be grayscale or color. |
| 335 | radius (int): Blur radius (in pixels). |
| 336 | |
| 337 | Returns: |
| 338 | np.ndarray: Blurred image. |
| 339 | """ |
| 340 | if radius == 0: |
| 341 | return image |
| 342 | kernel = disk_kernel(radius) |
| 343 | if image.ndim == 2: |
| 344 | blurred = fftconvolve(image, kernel, mode='same') |
| 345 | elif image.ndim == 3: |
| 346 | channels = [] |
| 347 | for i in range(image.shape[2]): |
| 348 | blurred_channel = fftconvolve(image[..., i], kernel, mode='same') |
| 349 | channels.append(blurred_channel) |
| 350 | blurred = np.stack(channels, axis=-1) |
| 351 | else: |
| 352 | raise ValueError("Image must be 2D or 3D.") |
| 353 | return blurred |
| 354 | |
| 355 | |
| 356 | def depth_of_field( |
no test coverage detected