MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / blur

Function blur

ldm/modules/image_degradation/bsrgan.py:128–142  ·  view source on GitHub ↗

x: image, NxcxHxW k: kernel, Nx1xhxw

(x, k)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected