赞
踩
由于版本问题,安装的最新版本的scikit-image,以下代码会报错:
from skimage.measure import compare_ssim, compare_psnr, compare_mse
将其改为:
- from skimage.metrics import mean_squared_error as compare_mse
- from skimage.metrics import peak_signal_noise_ratio as compare_psnr
- from skimage.metrics import structural_similarity as compare_ssim
即可正常使用,完整代码如下:
- from skimage.metrics import mean_squared_error as compare_mse
- from skimage.metrics import peak_signal_noise_ratio as compare_psnr
- from skimage.metrics import structural_similarity as compare_ssim
- import cv2
-
- img1 = cv2.imread('正确图像地址')
- img2 = cv2.imread('待比较图像地址')
-
- p = compare_psnr(img1, img2)
- s = compare_ssim(img1, img2, multichannel=True) # 对于多通道图像(RGB、HSV等)关键词multichannel要设置为True
- m = compare_mse(img1, img2)
-
- print('PSNR:{},SSIM:{},MSE:{}'.format(p, s, m))
注意图像地址要避免中文路径,否则可能出现“AttributeError: 'NoneType' object has no attribute 'shape'”等错误。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。