python Mean Squared Error vs. Structural Similarity Measure两种算法的图片比较
# 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/
python Mean Squared Error vs. Structural Similarity Measure两种算法的图片比较的更多相关文章
- python excel操作单元格复制和读取的两种方法
操作单元格 新建一个sheet, 单元格赋值(两种方法) 单元格A1赋值为’xiaxiaoxu’ 单元格A2赋值为‘xufengchai’ 打印A1和A2单元格的值(两种方法) #coding=utf ...
- Python通过pip方式安装第三方模块的两种方式
一:环境 python3.6 windows 10 二:常用命令 如果直接执行pip命令报错,说明pip不在path环境变量中 解决方法: python -m pip list 以下默认可直接使用pi ...
- python flask学习第2天 URL中两种方式传参
新创建项目 自己写个url映射到自定义的视图函数 在url中传递参数 app.py from flask import Flask app = Flask(__name__) @app.route ...
- Python将字符串转化为对应类名的两种方法
way first: 1 from django.utils.module_loading import import_string 2 ValidationError = import_string ...
- Python中求1到20平方的两种方法
#1.使用列表推导式 >>> [x**2 for x in range(1,21)] [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, ...
- python利用mongodb上传图片数据 : GridFS 与 bson两种方式
利用mongodb保存图片通常有两种方法,一种是将图片数据转化为二进制作为字典的键值对进行保存,另一种是利用mongodb提供的GridFS进行保存,两者各有利弊.性能方面的优劣未曾测试,无法进行评价 ...
- python 之 并发编程(开启子进程的两种方式,进程对象的属性)
第九章并发编程 同一个程序执行多次是多个进程 import time import os print('爹是:',os.getppid()) #父进程PID,(pycharm) print('me ...
- Python中斐波那契数列的四种写法
在这些时候,我可以附和着笑,项目经理是决不责备的.而且项目经理见了孔乙己,也每每这样问他,引人发笑.孔乙己自己知道不能和他们谈天,便只好向新人说话.有一回对我说道,“你学过数据结构吗?”我略略点一点头 ...
- Python开发【算法】:斐波那契数列两种时间复杂度
斐波那契数列 概述: 斐波那契数列,又称黄金分割数列,指的是这样一个数列:0.1.1.2.3.5.8.13.21.34.……在数学上,斐波纳契数列以如下被以递归的方法定义:F(0)=0,F(1)=1, ...
随机推荐
- win7+vs2010配置驱动开发环境(问题种种版...)
本来按照这个来做,能跑通helloworld,可是复杂的驱动就会出错....不知道什么原因,后来就直接用命令行来编译的. -------------------------------------- ...
- XDTIC2019招新笔试题 + 官方解答
腾讯创新俱乐部2019年招新笔试试题 [1] 小宗学长正在努力学习数论,他写下了一个奇怪的算式: \[ 2019^{2018^{2017^{\dots^{2^1}}}} \] 算式的结果一定很大, ...
- HDU 5052 /// 树链剖分+线段树区间合并
题目大意: 给定n (表示树有n个结点) 接下来n行给定n个点的点权(在这个点上买鸡或者卖鸡的价钱就是点权) 接下来n-1行每行给定 x y 表示x结点和y结点之间有一条边 给定q (表示有q个询问) ...
- 全球CMOS图像传感器厂商
近期,台湾地区的Yuanta Research发布报告,介绍了其对CMOS图像传感器(CIS)市场的看法,以及到2022年的前景预期. 从该研究报告可以看出,2018年全球CMOS图像传感器的市场规模 ...
- Nginx配置web服务
Nginx配置虚拟主机 虚拟主机概述 所谓虚拟主机,在web服务里就是一个独立的网站站点,这个站点对应独立的域名(也可以是IP或者端口),具有独立的程序及资源目录,可以独立的对外提供服务,继而给用户访 ...
- mysql 数据库基本命令
停止mysql服务:net stop mysql //管理员方式运行 启动mysql服务:net start mysql 进入数据库:mysql -u root -p 查看数据库:show ...
- 利用DNSQuery 进行DNS查询
#include <WinSock2.h> #include <WinDNS.h> #pragma comment (lib, "Dnsapi.lib") ...
- Java中的常量池
JVM中有: Class文件常量池.运行时常量池.全局字符串常量池.基本类型包装类对象 常量池 Class文件常量池: class文件是一组以字节为单位的二进制数据流,在java代码的编译期间,编写的 ...
- Model ModelMap ModelAndView
前言 Spring MVC在调用方法前会创建一个隐含的模型对象作为模型数据的存储容器. 如果方法的入参为ModelMap,Model,Map类型,Spring MVC会将隐含模型的引用传递给这些入参. ...
- Makefile 从入门到放弃
//如有侵权 请联系我进行删除 email:YZFHKM@163.com { 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作, ...