Generate disk kernel with given radius. Args: radius (int): Radius of the disk (in pixels). Returns: np.ndarray: (2*radius+1, 2*radius+1) normalized convolution kernel.
(radius: int)
| 307 | |
| 308 | |
| 309 | def disk_kernel(radius: int) -> np.ndarray: |
| 310 | """ |
| 311 | Generate disk kernel with given radius. |
| 312 | |
| 313 | Args: |
| 314 | radius (int): Radius of the disk (in pixels). |
| 315 | |
| 316 | Returns: |
| 317 | np.ndarray: (2*radius+1, 2*radius+1) normalized convolution kernel. |
| 318 | """ |
| 319 | # Create coordinate grid centered at (0,0) |
| 320 | L = np.arange(-radius, radius + 1) |
| 321 | X, Y = np.meshgrid(L, L) |
| 322 | # Generate disk: region inside circle with radius R is 1 |
| 323 | kernel = ((X**2 + Y**2) <= radius**2).astype(np.float32) |
| 324 | # Normalize the kernel |
| 325 | kernel /= np.sum(kernel) |
| 326 | return kernel |
| 327 | |
| 328 | |
| 329 | def disk_blur(image: np.ndarray, radius: int) -> np.ndarray: |