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

Function add_sharpening

ldm/modules/image_degradation/bsrgan.py:299–322  ·  view source on GitHub ↗

USM sharpening. borrowed from real-ESRGAN Input image: I; Blurry image: B. 1. K = I + weight * (I - B) 2. Mask = 1 if abs(I - B) > threshold, else: 0 3. Blur mask: 4. Out = Mask * K + (1 - Mask) * I Args: img (Numpy array): Input image, HWC, BGR; float32, [0, 1].

(img, weight=0.5, radius=50, threshold=10)

Source from the content-addressed store, hash-verified

297
298
299def add_sharpening(img, weight=0.5, radius=50, threshold=10):
300 """USM sharpening. borrowed from real-ESRGAN
301 Input image: I; Blurry image: B.
302 1. K = I + weight * (I - B)
303 2. Mask = 1 if abs(I - B) > threshold, else: 0
304 3. Blur mask:
305 4. Out = Mask * K + (1 - Mask) * I
306 Args:
307 img (Numpy array): Input image, HWC, BGR; float32, [0, 1].
308 weight (float): Sharp weight. Default: 1.
309 radius (float): Kernel size of Gaussian blur. Default: 50.
310 threshold (int):
311 """
312 if radius % 2 == 0:
313 radius += 1
314 blur = cv2.GaussianBlur(img, (radius, radius), 0)
315 residual = img - blur
316 mask = np.abs(residual) * 255 > threshold
317 mask = mask.astype('float32')
318 soft_mask = cv2.GaussianBlur(mask, (radius, radius), 0)
319
320 K = img + weight * residual
321 K = np.clip(K, 0, 1)
322 return soft_mask * K + (1 - soft_mask) * img
323
324
325def add_blur(img, sf=4):

Callers 1

degradation_bsrgan_plusFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected