x: image, NxcxHxW k: kernel, Nx1xhxw
(x, k)
| 125 | |
| 126 | |
| 127 | def blur(x, k): |
| 128 | ''' |
| 129 | x: image, NxcxHxW |
| 130 | k: kernel, Nx1xhxw |
| 131 | ''' |
| 132 | n, c = x.shape[:2] |
| 133 | p1, p2 = (k.shape[-2] - 1) // 2, (k.shape[-1] - 1) // 2 |
| 134 | x = torch.nn.functional.pad(x, pad=(p1, p2, p1, p2), mode='replicate') |
| 135 | k = k.repeat(1, c, 1, 1) |
| 136 | k = k.view(-1, 1, k.shape[2], k.shape[3]) |
| 137 | x = x.view(1, -1, x.shape[2], x.shape[3]) |
| 138 | x = torch.nn.functional.conv2d(x, k, bias=None, stride=1, padding=0, groups=n * c) |
| 139 | x = x.view(n, c, x.shape[2], x.shape[3]) |
| 140 | |
| 141 | return x |
| 142 | |
| 143 | |
| 144 | def gen_kernel(k_size=np.array([15, 15]), scale_factor=np.array([4, 4]), min_var=0.6, max_var=10., noise_level=0): |
nothing calls this directly
no outgoing calls
no test coverage detected