例如psnr方程:
import numpy as np
from imageio import imread
'''
测试psnr算法
2021.5.13
im1.shape:(687, 409) im2.shape:(687, 409)
33.72014101457756
输出:
im1.shape:(687, 409) im2.shape:(687, 409)
33.72014101457756
'''
def cal_psnr(im1,im2):
mse = (np.abs(im1-im2)**2).mean()
psnr = 10 * np.log10(255*255/mse)
return psnr
im1 = imread('../abc.png', pilmode='L') #
im2 = imread('../abc2.png', pilmode='L') #
print(f'im1.shape:{im1.shape} im2.shape:{im2.shape}')
print(cal_psnr(im1, im2))
imageio.imread可以代替scipy.misc.imread
用pilmode代替mode
用as_gray代替flatten
pilmode类型:
‘L’ (8-bit pixels, grayscale)
‘P’ (8-bit pixels, mapped to any other mode using a