########## 返回目录 - 信息隐藏技术(Python) ###
1. 客观图像质量指标 之 PSNR
可以参考用Python+OpenCV对比图像质量的几种方法,也可以自行编写代码,详情如下:
先安装 skimage
命令行:pip install scikit-image -i https://pypi.douban.com/simple --default-timeout=1000
import cv2
import numpy as np
from skimage.metrics import peak_signal_noise_ratio
def get_psnr(Ic, Im, IMax=256):
'''
Ic - The cover image
Im - The marked image
IMax - The number of grayscales
'''
diff = Ic.astype(np.float32)-Im.astype(np.float32)
MSE = np.sum(np.mean((np.power(diff, 2))))
if MSE < 1.0e-10:
return 100 # The max value for PSNR
psnr = -10*np.log10( MSE / ((IMax-1.0) ** 2) )
return psnr
if __name__ == '__main__':
Ic = cv2.imread('./monarch.png', cv2.IMREAD_GRAYSCALE)
Im = cv2.imread('./monarch_lsb.png', cv2.IMREAD_GRAYSCALE)
psnr = get_psnr(Ic, Im)
print('{:.4f}'.format(psnr))
psnr = peak_signal_noise_ratio(Ic, Im)
print('{:.4f}'.format(psnr))
输出结果
84.4392
84.4392
2. 综合主观与客观的图像质量指标 之 SSIM
参考用Python+OpenCV对比图像质量的几种方法,使用SSIM
import cv2
from skimage.metrics import structural_similarity
if __name__ == '__main__':
Ic = cv2.imread('./monarch.png', cv2.IMREAD_GRAYSCALE)
Im = cv2.imread('./monarch_lsb.png', cv2.IMREAD_GRAYSCALE)
ssim = structural_similarity(Ic, Im)
print('{:.8f}'.format(ssim))
输出结果
0.99999972
########## 返回目录 - 信息隐藏技术(Python) ###