python简单实现的psnr和mpsnr

代码

import cv2
import math
import numpy as np
def psnr(img1, img2):
    mse = np.mean((img1 / 1023 - img2 / 1023) ** 2)
    if mse < 1.0e-10:
        return 100
    PIXEL_MAX = 1
    return 20 * math.log10(PIXEL_MAX / math.sqrt(mse))
def mpsnr(x_true, x_pred):
     n_bands = x_true.shape[2]
     p = [psnr(x_true[:, :, k], x_pred[:, :, k]) for k in range(n_bands)]
     return np.mean(p)
img2 = cv2.imread('D:/project_hdr/hdr-expandnet/test_data_hdr/5892_256x256.exr')
image_e_2 = cv2.imread('D:/project_hdr/hdr-expandnet/test_data_ldr/933/5892_256x256_prediction.hdr')
e2 = (mpsnr(img2,image_e_2))
print(e2)

这里我测试的是exr图片,普通图片要把1023改成255就可以了
结果截图
在这里插入图片描述

你可能感兴趣的:(计算机视觉)