###ソースコード
#import the necessary packages from skimage.measure import structural_similarity as ssim import matplotlib.pyplot as plt import numpy as np import cv2 %matplotlib inline def mse(imageA, imageB): #the 'Mean Squared Error' between the two images is the #sum of the squared difference between the two images; #NOTE: the two images must have the same dimension err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2) err /= float(imageA.shape[0] * imageA.shape[1]) #return the MSE, the lower the error, the more "similar" #the two images are return err def compare_images(imageA, imageB, title): #compute the mean squared error and structural similarity #index for the images m = mse(imageA, imageB) s = ssim(imageA, imageB) #setup the figure fig = plt.figure(title) plt.suptitle("MSE: %.2f, SSIM: %.2f" % (m, s)) #show first image ax = fig.add_subplot(1, 2, 1) plt.imshow(imageA, cmap = plt.cm.gray) plt.axis("off") #show the second image ax = fig.add_subplot(1, 2, 2) plt.imshow(imageB, cmap = plt.cm.gray) plt.axis("off") #show the images plt.show() #load the images -- the original, the original + contrast, #and the original + photoshop original = cv2.imread("resize/re_pic006.jpg") contrast = cv2.imread("resize/re_pic005.jpg") shopped = cv2.imread("resize/re_pic003.jpg") #convert the images to grayscale original = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY) contrast = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY) shopped = cv2.cvtColor(shopped, cv2.COLOR_BGR2GRAY) #initialize the figure fig = plt.figure("Images") images = ("Original", original), ("Contrast", contrast), ("Photoshopped", shopped) #loop over the images for (i, (name, image)) in enumerate(images): #show the image ax = fig.add_subplot(1, 3, i + 1) ax.set_title(name) plt.imshow(image, cmap = plt.cm.gray) plt.axis("off") #show the figure plt.show() #compare the images compare_images(original, original, "Original vs. Original") compare_images(original, contrast, "Original vs. Contrast") compare_images(original, shopped, "Original vs. Photoshopped")
やったこと
http://kamonohashiperry.com/archives/699
上記のページの「以下は、類似度計算の実行用コードとなります。」
以降のプログラムを実行した際、
以下のようなエラーが起こりました。
原因はなんでしょうか?ご教示お願いします。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "C:\Users\Owner\compare.py", line 2, in <module> from skimage.measure import structural_similarity as ssim ImportError: cannot import name structural_similarity
試したこと
%matplotlib inlineだと「%」にinvalid syntaxエラーが吐かれた。
なので#でコメント化した。
python3.7でやっていたので元ページと同じくpython2.7にした。
補足情報(FW/ツールのバージョンなど)
pip install ssimをやって、
ssim-0.2.2
をインストールした。

回答1件
あなたの回答
tips
プレビュー