r"""Function that returns Gaussian filter matrix coefficients. Args: kernel_size (Tuple[int, int]): filter sizes in the x and y direction. Sizes should be odd and positive. sigma (Tuple[int, int]): gaussian standard deviation in the x and y direction. Retu
(kernel_size, sigma)
| 273 | return window_1d |
| 274 | |
| 275 | def get_gaussian_kernel2d(kernel_size, sigma): |
| 276 | r"""Function that returns Gaussian filter matrix coefficients. |
| 277 | |
| 278 | Args: |
| 279 | kernel_size (Tuple[int, int]): filter sizes in the x and y direction. |
| 280 | Sizes should be odd and positive. |
| 281 | sigma (Tuple[int, int]): gaussian standard deviation in the x and y |
| 282 | direction. |
| 283 | |
| 284 | Returns: |
| 285 | Tensor: 2D tensor with gaussian filter matrix coefficients. |
| 286 | |
| 287 | Shape: |
| 288 | - Output: :math:`(\text{kernel_size}_x, \text{kernel_size}_y)` |
| 289 | |
| 290 | Examples:: |
| 291 | |
| 292 | >>> kornia.image.get_gaussian_kernel2d((3, 3), (1.5, 1.5)) |
| 293 | tensor([[0.0947, 0.1183, 0.0947], |
| 294 | [0.1183, 0.1478, 0.1183], |
| 295 | [0.0947, 0.1183, 0.0947]]) |
| 296 | |
| 297 | >>> kornia.image.get_gaussian_kernel2d((3, 5), (1.5, 1.5)) |
| 298 | tensor([[0.0370, 0.0720, 0.0899, 0.0720, 0.0370], |
| 299 | [0.0462, 0.0899, 0.1123, 0.0899, 0.0462], |
| 300 | [0.0370, 0.0720, 0.0899, 0.0720, 0.0370]]) |
| 301 | """ |
| 302 | if not isinstance(kernel_size, tuple) or len(kernel_size) != 2: |
| 303 | raise TypeError("kernel_size must be a tuple of length two. Got {}" |
| 304 | .format(kernel_size)) |
| 305 | if not isinstance(sigma, tuple) or len(sigma) != 2: |
| 306 | raise TypeError("sigma must be a tuple of length two. Got {}" |
| 307 | .format(sigma)) |
| 308 | ksize_x, ksize_y = kernel_size |
| 309 | sigma_x, sigma_y = sigma |
| 310 | kernel_x = get_gaussian_kernel(ksize_x, sigma_x) |
| 311 | kernel_y = get_gaussian_kernel(ksize_y, sigma_y) |
| 312 | kernel_2d = torch.matmul( |
| 313 | kernel_x.unsqueeze(-1), kernel_y.unsqueeze(-1).t()) |
| 314 | return kernel_2d |
| 315 | |
| 316 | def gaussian_blur(x, kernel_size=(5,5), sigma=(1.3,1.3)): |
| 317 | b, c, h, w = x.shape |
no test coverage detected