| 16 | |
| 17 | |
| 18 | def main(): |
| 19 | # Loading images (original image and compressed image) |
| 20 | orignal_image = cv2.imread("orignal_image.png", 1) |
| 21 | compressed_image = cv2.imread("compressed_image.png", 1) |
| 22 | |
| 23 | # Getting image height and width |
| 24 | height, width = orignal_image.shape[:2] |
| 25 | |
| 26 | orignalPixelAt = calculate(orignal_image) |
| 27 | compressedPixelAt = calculate(compressed_image) |
| 28 | |
| 29 | diff = orignalPixelAt - compressedPixelAt |
| 30 | error = np.sum(np.abs(diff) ** 2) |
| 31 | |
| 32 | error = error / (height * width) |
| 33 | |
| 34 | # MSR = error_sum/(height*width) |
| 35 | PSNR = -(10 * math.log10(error / (255 * 255))) |
| 36 | |
| 37 | print("PSNR value is {}".format(PSNR)) |
| 38 | |
| 39 | |
| 40 | if __name__ == "__main__": |