williamfzc/stagesepx

ImportError: cannot import name 'compare_ssim' from 'skimage.measure'

williamfzc opened this issue ยท 5 comments

it has been removed in skimage 0.18
https://scikit-image.org/docs/dev/api_changes.html

fix soon in findit package

fixed

how to fix scikit compare ssim problem if it has been removed?

how to fix scikit compare ssim problem if it has been removed?

Their functionality still exists, but under the new skimage.metrics submodule under different names.

Changed in version 0.16: This function was renamed from skimage.measure.compare_ssim to skimage.metrics.structural_similarity.

For the Structural similarity I'm using this and it's hopefully working ::

import matplotlib.pyplot as plt, numpy as np
import cv2
import torch
from skimage.metrics import structural_similarity as ssim

def load_images(filename):
# read image using OpenCV
img = cv2.imread(filename)
# convert color scheme from BGR to RGB
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
return img

def tensorify(img):
# convert image to tensor format and normalize pixel values between 0 and 1
img_tensor = torch.from_numpy(img.transpose((2, 0, 1))) / 255
return img_tensor

img1 = load_images("ssim2.jpg") # helper function to load images

img2 = load_images("ssim1.jpg")

_img1 = tensorify(img1) # helper function to convert cv2 image to tensors
_img2 = tensorify(img2)

Convert PyTorch tensors to numpy arrays

img1_np = _img1.numpy()
img2_np = _img2.numpy()

Compute SSIM score with win_size=3

ssim_score = ssim(img1_np, img2_np, multichannel=True, win_size=3)
print("True vs False Image SSIM Score: ", np.round(ssim_score*100,2) ,"%")