PSNR和SSIM计算的代码实现
注意:
1.以下参数img的数据类型为:numpy.ndarray
2.img的维度为:[H,W,C]
3.像素值范围在【0-255】
- PSNR
def calculate_psnr(img1, img2):
# img1 and img2 have range [0, 255]
img1 = img1.astype(np.float64)
img2 = img2.astype(np.float64)
# print(img1)
# print('img1-2')
# print(img2)
mse = np.mean((img1 - img2)**2)
# print(mse)
if mse == 0:
return float('inf')
return 20 * math.log10(255.0 / math.sqrt(mse))
- SSIM
def ssim(img1, img2):
C1 =