【问题标题】:ssim image compare error ''window_shape incompatible with arr_in.shape"ssim 图像比较错误“window_shape 与 arr_in.shape 不兼容”
【发布时间】:2015-11-11 16:16:01
【问题描述】:

我想用ssim 比较两张图片的相似度。 我收到此错误 window_shape is incompatible with arr_in.shape 。 为什么? (什么意思?)

from skimage.measure import structural_similarity as ssim
from skimage import io

img1 = io.imread('http://pasteio.com/m85cc2eed18c661bf8a0ea7e43779e742')
img2 = io.imread('http://pasteio.com/m1d45b9c70afdb576f1e3b33d342bf7d0')

ssim( img1, img2 )

Traceback(最近一次调用最后一次):文件“”,第 1 行,in 文件 “/var/www/wt/local/lib/python2.7/site-packages/skimage/measure/_structural_similarity.py”, 第 58 行,在结构相似性中 XW = view_as_windows(X, (win_size, win_size)) 文件 "/var/www/wt/local/lib/python2.7/site-packages/skimage/util/shape.py", 第 221 行,在 view_as_windows raise ValueError("window_shape is incompatible with arr_in.shape") ValueError: window_shape is incompatible with arr_in.shape

即使我两次输入同一个文件,我也会遇到同样的错误ssim(img1,img1)

【问题讨论】:

  • 请提供您的测试图像的链接。
  • @StefanvanderWalt 已更新。现在包括图片的网址。
  • 你正在处理彩色图像,所以你想要ssim(img1, img2, multichannel=True)
  • TypeError: structural_similarity() got an unexpected keyword argument 'multichannel' ,在当前稳定版本 (0.11.3) 中不可用。尝试安装 dev 版本,但由于依赖问题而失败
  • 然后先将图像转换为灰色:from skimage import color; img1 = color.rgb2gray(img1)

标签: python scikit-image scikits


【解决方案1】:

您需要确保您的图片大小相同,以便与 scikit 的 ssim 进行比较:

from skimage.measure import compare_ssim
from skimage.transform import resize
from scipy.ndimage import imread
import numpy as np

# resized image sizes
height = 2**10
width = 2**10

a = imread('a.jpg', flatten=True).astype(np.uint8)
b = imread('b.jpg', flatten=True).astype(np.uint8)
a = resize(a, (height, width))
b = resize(b, (height, width))

sim, diff = compare_ssim(a, b, full=True)

【讨论】:

    猜你喜欢
    • 2021-11-16
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多