(img1, img2, border=0)
| 619 | # PSNR |
| 620 | # -------------------------------------------- |
| 621 | def 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 | # -------------------------------------------- |
nothing calls this directly
no outgoing calls
no test coverage detected