TypeError: structural_similarity() takes 2 positional arguments but 8 were given

Viewed 1544

When I calculate the similarity between two grayscale images in python and opencv, the function called compare_ssim() is reported incorrectly.

gray1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
(score, diff) = compare_ssim(gray1, gray2, full=True)

The error message is as follows:

TypeError: structural_similarity() takes 2 positional arguments but 8 were given

This is a function from library. From the _structural_similarity.py file.The directory is \skimage\measure\_structural_similarity.py.

def compare_ssim(X, Y, win_size=None, gradient=False,
                 data_range=None, multichannel=False, gaussian_weights=False,
                 full=False, **kwargs):
    warn('DEPRECATED: skimage.measure.compare_ssim has been moved to '
         'skimage.metrics.structural_similarity. It will be removed from '
         'skimage.measure in version 0.18.', stacklevel=2)
       return structural_similarity(X, Y, win_size, gradient,
                                 data_range, multichannel, gaussian_weights, 
                                 full, **kwargs)

return line, error message is displayed in this line.

And structural_similarity().The directory of this function is \skimage\metrics\_structural_similarity.py, the function is as follows:

def structural_similarity(im1, im2,
                          *,
                          win_size=None, gradient=False, data_range=None,
                          multichannel=False, gaussian_weights=False,
                          full=False, **kwargs):

What is the problem, why is this?

3 Answers
from skimage.metrics import structural_similarity

Do try...

I tried using this :

from skimage.metrics import structural_similarity as ssim
...
s = ssim(gray_image_1,gray_image_2)

here, gray_image_1.shape = gray_image_2.shape = (420,420). This worked for me (python 3.6.6).

`

Thank you for your patience. I have solved this problem. It should be a function call error.when I replace the header file 'from skimage.measures import compare_ssim' with from skimage.metrics import structural_similarity, and replace the function call with a (score, diff) = structural_similarity(gray1, gray2, full=True), compiled successfully

Related