Как мне сравнить SSIM между одним изображением и многими другими, используя Python?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как мне сравнить SSIM между одним изображением и многими другими, используя Python?

Сообщение Anonymous »

Используя эту замечательную страницу: https://www.pyimagesearch.com/2014/09/1 ... wo-images/
, я могу найти SSIM между тремя изображениями

Код: Выделить всё

# import the necessary packages
from skimage.measure import structural_similarity as ssim
import matplotlib.pyplot as plt
import numpy as np
import cv2 as cv

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 = cv.imread("images/jp_gates_original.png")
contrast = cv.imread("images/jp_gates_contrast.png")
shopped = cv.imread("images/jp_gates_photoshopped.png")

# convert the images to grayscale
original = cv.cvtColor(original, cv.COLOR_BGR2GRAY)
contrast = cv.cvtColor(contrast, cv.COLOR_BGR2GRAY)
shopped = cv.cvtColor(shopped, cv.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")
Однако я не совсем понимаю, как применить это ко многим изображениям. В частности, как я могу взять одно изображение (тестовое изображение) из папки сотен изображений и вычислить MSE/SSIM между тестовыми изображениями и всеми остальными изображениями?
Спасибо! п>

Подробнее здесь: https://stackoverflow.com/questions/545 ... ing-python
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»