简体   繁体   中英

I have two matrices that I have converted to a grayscale image and I want to find the mean SSIM value between them (python)

For example I have:

X = [[1,2,3],[4,5,6]]
Y = [[1,4,7],[5,5,1]]

a=np.array(X)
grayA=(a-np.amin(a))/(np.amax(a)-np.amin(a))

b=np.array(Y)
grayB=(b-np.amin(b))/(np.amax(b)-np.amin(b))

However, when I do

compare_ssim(grayA, grayB)

I get the error

ValueError: win_size exceeds image extent.  If the input is a multichannel (color) image, set multichannel=True.

I tried

compare_ssim(grayA, grayB, multichannel = True)

but I am still getting the same error.

The error is produced because the default value of win_size is 7 and

np.any((np.asarray(grayA.shape) - win_size) < 0)

To solve the problem, you should define win_size to be odd and smaller than any of the image dimensions. So, in your example, it should be win_size=1 .

However, when win_size is equal to 1, you need to set use_sample_covariance=False because if not, the code needs to divide by 0. Therefore, your example would work using

compare_ssim(grayA, grayB, win_size=1, use_sample_covariance=False)

The problem vanishes if your images are 7x7 or larger. For instance:

X = np.random.rand(7,7)
Y = np.random.rand(7,7)
compare_ssim(X, Y)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM