Skip to content

Commit

Permalink
Create PSNR.py
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhuang31 authored Oct 31, 2016
1 parent 5d11cbe commit 46b3ef7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions PSNR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import cv2
import math
import numpy


def PSNR(img1, img2):
D = numpy.array(img1 - img2, dtype=numpy.int64)
D[:, :] = D[:, :]**2
RMSE = D.sum()/img1.size
psnr = 10*math.log10(float(255.**2)/RMSE)
return psnr

if __name__ == "__main__":
img1 = cv2.imread("original 2D4F.bmp", cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread("Basic2.jpg", cv2.IMREAD_GRAYSCALE)
psnr = PSNR(img1, img2)
print ("The PSNR between the two img of the two is %f" % psnr)

img1 = cv2.imread("original 2D4F.bmp", cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread("Final2.jpg", cv2.IMREAD_GRAYSCALE)
psnr = PSNR(img1, img2)
print ("The PSNR between the two img of the two is %f" % psnr)

0 comments on commit 46b3ef7

Please sign in to comment.