Python计算两图相似性-SSIM、PSNR,MSE
1、简介
SSIM:值越接近1,图像越相似
PSNR:PSNR越大说明失真越少,生成图像的质量越好
MSE:MSE值越小,图像越相似
2、代码示例
测试图片点击进行下载:Image
# -*- coding:UTF-8 -*- from skimage.metrics import structural_similarity as SSIM from skimage.metrics import peak_signal_noise_ratio as PSNR from skimage.metrics import mean_squared_error as MSE import cv2 def get_spm(img_cp1, img_cp2): psnr = PSNR(img_cp1, img_cp2) ssim = SSIM(img_cp1, img_cp2, multichannel=True, channel_axis=2) mse = MSE(img_cp1, img_cp2) return psnr, ssim, mse img_cp1 = cv2.imread("WD1.png") img_cp2 = cv2.imread("WD2.png") psnr, ssim, mse = get_spm(img_cp1, img_cp2) print("PSNR:{}\nSSIM:{}\nMSE:{}".format(psnr, ssim, mse))