import cv2 import numpy as np import math def psnr(target, ref): #将图像格式转为float64 target_data = np.array(target, dtype=np.float64) ref_data = np.array(ref,dtype=np.float64) # 直接相减,求差值 diff = ref_data - target_data # 按第三个通道顺序把三维矩阵拉平 diff = diff.flatten('C') # 计算MSE值 rmse = math.sqrt(np.mean(diff ** 2.)) # 精度 eps = np.finfo(np.float64).eps if(rmse == 0): rmse = eps return 20*math.log10(255.0/rmse) IMG_1 = cv2.imread("yuer.jpg",0) IMG_2 = cv2.imread("june.jpg",0) IMG_1 = np.resize(IMG_1, (100,100)) IMG_2 = np.resize(IMG_2, (100,100)) print(psnr(IMG_1,IMG_2))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)