Added PSNR calculator for image compression quality analysis (#475)

* Added PSNR calculator for image compression quality analysis

* Removed unused variables and redundancy
This commit is contained in:
Vasu Tomar 2018-10-19 17:26:08 +05:30 committed by Harshil
parent 315a357c1b
commit 90979777c7
4 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
import numpy as np
import math
import cv2
def Representational(r,g,b):
return (0.299*r+0.287*g+0.114*b)
def calculate(img):
b,g,r = cv2.split(img)
pixelAt = Representational(r,g,b)
return pixelAt
def main():
#Loading images (orignal image and compressed image)
orignal_image = cv2.imread('orignal_image.png',1)
compressed_image = cv2.imread('compressed_image.png',1)
#Getting image height and width
height,width = orignal_image.shape[:2]
orignalPixelAt = calculate(orignal_image)
compressedPixelAt = calculate(compressed_image)
diff = orignalPixelAt - compressedPixelAt
error = np.sum(np.abs(diff) ** 2)
error = error/(height*width)
#MSR = error_sum/(height*width)
PSNR = -(10*math.log10(error/(255*255)))
print("PSNR value is {}".format(PSNR))
if __name__ == '__main__':
main()

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB