r"""Creates a binary kernel to extract the patches. If the window size is HxW will create a (H*W)xHxW kernel.
(window_size)
| 378 | return F.conv2d(x, kernel, padding=padding, stride=1, groups=c) |
| 379 | |
| 380 | def _compute_binary_kernel(window_size): |
| 381 | r"""Creates a binary kernel to extract the patches. If the window size |
| 382 | is HxW will create a (H*W)xHxW kernel. |
| 383 | """ |
| 384 | window_range = window_size[0] * window_size[1] |
| 385 | kernel: torch.Tensor = torch.zeros(window_range, window_range) |
| 386 | for i in range(window_range): |
| 387 | kernel[i, i] += 1.0 |
| 388 | return kernel.view(window_range, 1, window_size[0], window_size[1]) |
| 389 | |
| 390 | def median_blur(x, kernel_size=(3,3)): |
| 391 | b, c, h, w = x.shape |