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

Function blur

ldm/modules/image_degradation/bsrgan_light.py:127–141  ·  view source on GitHub ↗

x: image, NxcxHxW k: kernel, Nx1xhxw

(x, k)

Source from the content-addressed store, hash-verified

125
126
127def 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
144def 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