Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssim image compare error ''window_shape incompatible with arr_in.shape"

I want to use ssim to compare similarity in 2 images. I'm getting this error window_shape is incompatible with arr_in.shape . Why? (What does it mean?)

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 (most recent call last): File "", line 1, in File "/var/www/wt/local/lib/python2.7/site-packages/skimage/measure/_structural_similarity.py", line 58, in structural_similarity XW = view_as_windows(X, (win_size, win_size)) File "/var/www/wt/local/lib/python2.7/site-packages/skimage/util/shape.py", line 221, in view_as_windows raise ValueError("window_shape is incompatible with arr_in.shape") ValueError: window_shape is incompatible with arr_in.shape

I get the same error even when I feed it the same file twice ssim(img1,img1)

like image 508
Alex Avatar asked Aug 18 '15 16:08

Alex


1 Answers

You need to make sure your images are the same size to compare them with scikit's 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)
like image 137
duhaime Avatar answered Oct 27 '22 00:10

duhaime