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

Function calculate_psnr

ldm/modules/image_degradation/utils_image.py:621–636  ·  view source on GitHub ↗
(img1, img2, border=0)

Source from the content-addressed store, hash-verified

619# PSNR
620# --------------------------------------------
621def calculate_psnr(img1, img2, border=0):
622 # img1 and img2 have range [0, 255]
623 #img1 = img1.squeeze()
624 #img2 = img2.squeeze()
625 if not img1.shape == img2.shape:
626 raise ValueError('Input images must have the same dimensions.')
627 h, w = img1.shape[:2]
628 img1 = img1[border:h-border, border:w-border]
629 img2 = img2[border:h-border, border:w-border]
630
631 img1 = img1.astype(np.float64)
632 img2 = img2.astype(np.float64)
633 mse = np.mean((img1 - img2)**2)
634 if mse == 0:
635 return float('inf')
636 return 20 * math.log10(255.0 / math.sqrt(mse))
637
638
639# --------------------------------------------

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected