r"""Creates a binary kernel to extract the patches. If the window size is HxW will create a (H*W)xHxW kernel.
(window_size)
| 321 | return F.conv2d(x, kernel, padding=padding, stride=1, groups=c) |
| 322 | |
| 323 | def _compute_binary_kernel(window_size): |
| 324 | r"""Creates a binary kernel to extract the patches. If the window size |
| 325 | is HxW will create a (H*W)xHxW kernel. |
| 326 | """ |
| 327 | window_range = window_size[0] * window_size[1] |
| 328 | kernel: torch.Tensor = torch.zeros(window_range, window_range) |
| 329 | for i in range(window_range): |
| 330 | kernel[i, i] += 1.0 |
| 331 | return kernel.view(window_range, 1, window_size[0], window_size[1]) |
| 332 | |
| 333 | def median_blur(x, kernel_size=(3,3)): |
| 334 | b, c, h, w = x.shape |