Created
July 10, 2017 02:41
-
-
Save minhokim0201/7b6655fcfcdb4963b44572a1236c46ae to your computer and use it in GitHub Desktop.
Compare Two Picture
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
# http://www.pyimagesearch.com/2014/09/15/python-compare-two-images/ | |
# scikit-image: http://scikit-image.org | |
# pip3 install -U scikit-image | |
import matplotlib | |
matplotlib.use('TkAgg') | |
import skimage.measure | |
import matplotlib.pyplot | |
import matplotlib.image | |
def compare_images(imageFileA, imageFileB, title): | |
# load the images | |
imageA = matplotlib.image.imread(imageFileA) | |
imageB = matplotlib.image.imread(imageFileB) | |
# http://scikit-image.org/docs/stable/api/skimage.measure.html | |
n = skimage.measure.compare_nrmse(imageA, imageB) | |
p = skimage.measure.compare_psnr(imageA, imageB) | |
s = skimage.measure.compare_ssim(imageA, imageB, multichannel=True) | |
# setup the figure | |
fig = matplotlib.pyplot.figure(title, figsize=(7, 7)) | |
matplotlib.pyplot.suptitle("NRMSE: %.2f, PSNR: %.2f, SSIM: %.2f" % (n, p, s)) | |
# show first image | |
ax = fig.add_subplot(1, 2, 1) | |
matplotlib.pyplot.imshow(imageA) | |
matplotlib.pyplot.axis("off") | |
# show the second image | |
ax = fig.add_subplot(1, 2, 2) | |
matplotlib.pyplot.imshow(imageB) | |
matplotlib.pyplot.axis("off") | |
# show the images | |
matplotlib.pyplot.show() | |
# compare the images | |
compare_images("images/apple.jpg", "images/orange.jpg", "Original vs. Contrast") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment