# by movie on 2019/12/18
import matplotlib.pyplot as plt
import numpy as np
from skimage import measure
import cv2
# import the necessary packages 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() # load the images -- the original, the original + contrast,
# and the original + photoshop
original = cv2.imread("images/trumpA689.jpg")
contrast = cv2.imread("images/trumpA690.jpg")
shopped = cv2.imread("images/trumpA748.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")

参考:https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/

最新文章

  1. 一键生成APP官网
  2. RabbitMQ 高可用集群搭建及电商平台使用经验总结
  3. SQL Server代理(2/12):作业步骤和子系统
  4. [LintCode] Wiggle Sort 扭动排序
  5. android WebView问题
  6. 解决SaveChanges会Hold住之前的错误的问题
  7. oracle 建立视图,创建用户并授予查询权限
  8. java虚拟机内存分析
  9. css一长串连续英文字符的换行
  10. Linux_window与linux之间文件互传,上传下载
  11. HDOJ 5639 Transform
  12. 在IT行业获得成功 你只需一项技能[转]
  13. HBase系列文章(转)
  14. Java基础—基础语法与常用命令
  15. 3.3V电源LDO
  16. 08.基于IDEA+Spring+Maven搭建测试项目--Maven的配置文件settings.xml
  17. 【Java】 大话数据结构(10) 查找算法(1)(顺序、二分、插值、斐波那契查找)
  18. TabLayout基本属性全解
  19. c++官方文档-命名空间
  20. 虚拟化 - kvm安装

热门文章

  1. 顺时针打印矩阵元素(python实现)
  2. 重启集群的时候发现HBase的HRegionServer 服务启动失败
  3. 循环神经网络RNN
  4. 哈理工赛 H-小乐乐学数学 /// 筛法得素数表+树状数组
  5. POJ 3525 /// 半平面交 模板
  6. Ansible配置及使用
  7. FCC——相关练习
  8. 分布式唯一ID实现
  9. 使用Element的upload上传组件,不使用action属性上传
  10. php 引用文件