当前位置:   article > 正文

scikit-image 0.18.0版本计算PSNR、SSIM、MSE(Python代码)_scikit learn psnr

scikit learn psnr

由于版本问题,安装的最新版本的scikit-image,以下代码会报错:

from skimage.measure import compare_ssim, compare_psnr, compare_mse

将其改为:

  1. from skimage.metrics import mean_squared_error as compare_mse
  2. from skimage.metrics import peak_signal_noise_ratio as compare_psnr
  3. from skimage.metrics import structural_similarity as compare_ssim

即可正常使用,完整代码如下:

  1. from skimage.metrics import mean_squared_error as compare_mse
  2. from skimage.metrics import peak_signal_noise_ratio as compare_psnr
  3. from skimage.metrics import structural_similarity as compare_ssim
  4. import cv2
  5. img1 = cv2.imread('正确图像地址')
  6. img2 = cv2.imread('待比较图像地址')
  7. p = compare_psnr(img1, img2)
  8. s = compare_ssim(img1, img2, multichannel=True) # 对于多通道图像(RGB、HSV等)关键词multichannel要设置为True
  9. m = compare_mse(img1, img2)
  10. print('PSNR:{},SSIM:{},MSE:{}'.format(p, s, m))

注意图像地址要避免中文路径,否则可能出现“AttributeError: 'NoneType' object has no attribute 'shape'”等错误。

参考文章:OpenCV-Python——图像PSNR、SSIM、MSE计算_米开朗琪罗儿的博客-CSDN博客

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/960894
推荐阅读
相关标签
  

闽ICP备14008679号