This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage import measure | |
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 = measure.compare_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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment