Skip to content

Commit

Permalink
Fix crash when images are identical
Browse files Browse the repository at this point in the history
  • Loading branch information
aizvorski committed Mar 11, 2015
1 parent 41ec2df commit 71d6c9c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions psnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import math

def psnr(img1, img2):
mse = numpy.mean( (img1 - img2) ** 2 )
PIXEL_MAX = 255.0
return 20 * math.log10(PIXEL_MAX / math.sqrt(mse))
mse = numpy.mean( (img1 - img2) ** 2 )
if mse == 0:
return 100
PIXEL_MAX = 255.0
return 20 * math.log10(PIXEL_MAX / math.sqrt(mse))

0 comments on commit 71d6c9c

Please sign in to comment.