ssim image比较错误''window_shape与arr_in.shape不兼容“

时间:2015-08-18 16:01:27

标签: python scikit-image scikits

我想使用ssim比较2张图片中的相似度。 我收到此错误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中       引发ValueError(“window_shapearr_in.shape不兼容”)ValueError:window_shape与   arr_in.shape

即使我将同一个文件同时输入ssim(img1,img1)

,我也会收到同样的错误

1 个答案:

答案 0 :(得分: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)