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

1

6

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)

Owlish answered 18/8, 2015 at 16:1 Comment(6)
Please provide a link to your test images.Flytrap
@StefanvanderWalt updated. now includes url to images.Owlish
You are working with color images, so you want ssim(img1, img2, multichannel=True)Flytrap
TypeError: structural_similarity() got an unexpected keyword argument 'multichannel' , not available in the current stable release (0.11.3) . Tried to install the dev release, but fails due to dependency issuesOwlish
Then convert your images to gray first: from skimage import color; img1 = color.rgb2gray(img1) etc.Flytrap
bedankt. That seems to work and good enough for what I want to do.Owlish
B
3

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)
Boodle answered 1/4, 2018 at 12:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.