SSIM是一种衡量两幅图片相似度的指标。
出处来自于2004年的一篇TIP,
标题为:Image Quality Assessment: From Error Visibility to Structural Similarity
地址为:https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=1284395

与PSNR一样,SSIM也经常用作图像质量的评价。


先了解SSIM的输入
SSIM的输入就是两张图像,我们要得到其相似性的两张图像。其中一张是未经压缩的无失真图像(即ground truth),另一张就是你恢复出的图像。所以,SSIM可以作为super-resolution质量的指标。
假设我们输入的两张图像分别是x和y,那么
SSIM(x,y)=[l(x,y)]α[c(x,y)]β[s(x,y)]γ−−−(1)SSIM(x,y)=[l(x,y)]^\alpha[c(x,y)]^\beta[s(x,y)]^\gamma ---(1)SSIM(x,y)=[l(x,y)]α[c(x,y)]β[s(x,y)]γ−−−(1)
α>0\alpha>0α>0, β>0\beta>0β>0,and γ>0\gamma>0γ>0.
式1是SSIM的数学定义,其中:
l(x,y)=2μxμy+c1μx2+μy2+c1,l(x,y)=\frac{2\mu_x\mu_y+c_1}{\mu_x^2+\mu_y^2+c_1},l(x,y)=μx2​+μy2​+c1​2μx​μy​+c1​​,
c(x,y)=2σxy+c2σx2+σy2+c2,c(x,y)=\frac{2\sigma_{xy}+c_2}{\sigma_x^2+\sigma_y^2+c_2},c(x,y)=σx2​+σy2​+c2​2σxy​+c2​​,
s(x,y)=σxy+c3σxσy+c3s(x,y)=\frac{\sigma_{xy}+c_3}{\sigma_x\sigma_y+c_3}s(x,y)=σx​σy​+c3​σxy​+c3​​
其中l(x, y)是亮度比较,c(x,y)是对比度比较,s(x,y)是结构比较。μx\mu_xμx​和μy\mu_yμy​分别代表x,y的平均值,σx\sigma_xσx​和σy\sigma_yσy​分别代表x,y的标准差。σxy\sigma_{xy}σxy​代表x和y的协方差。而c1c_1c1​,c2c_2c2​,c3c_3c3​分别为常数,避免分母为0带来的系统错误。
在实际工程计算中,我们一般设定α=β=γ=1\alpha=\beta=\gamma=1α=β=γ=1,以及c3=c2/2c_3=c_2/2c3​=c2​/2,可以将SSIM简化为下:

SSIM(x,y)=(2μxμy+c1)(σxy+c2)(μx2+μy2+c1)(σx2+σy2+c2)SSIM(x, y)= \frac{(2\mu_x\mu_y+c_1)(\sigma_{xy}+c_2)}{(\mu_x^2+\mu_y^2+c_1)(\sigma_x^2+\sigma_y^2+c_2)}SSIM(x,y)=(μx2​+μy2​+c1​)(σx2​+σy2​+c2​)(2μx​μy​+c1​)(σxy​+c2​)​
总结

  1. SSIM具有对称性,即SSIM(x,y)=SSIM(y,x)
  2. SSIM是一个0到1之间的数,越大表示输出图像和无失真图像的差距越小,即图像质量越好。当两幅图像一模一样时,SSIM=1;

如PSNR一样,SSIM这种常用计算函数也被tensorflow收编了,我们只需在tf中调用ssim就可以了:

tf.image.ssim(x, y, 255)

源代码如下:

def ssim(img1, img2, max_val):"""Computes SSIM index between img1 and img2.This function is based on the standard SSIM implementation from:Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Imagequality assessment: from error visibility to structural similarity. IEEEtransactions on image processing.Note: The true SSIM is only defined on grayscale.  This function does notperform any colorspace transform.  (If input is already YUV, then it willcompute YUV SSIM average.)Details:- 11x11 Gaussian filter of width 1.5 is used.- k1 = 0.01, k2 = 0.03 as in the original paper.The image sizes must be at least 11x11 because of the filter size.Example:# Read images from file.im1 = tf.decode_png('path/to/im1.png')im2 = tf.decode_png('path/to/im2.png')# Compute SSIM over tf.uint8 Tensors.ssim1 = tf.image.ssim(im1, im2, max_val=255)# Compute SSIM over tf.float32 Tensors.im1 = tf.image.convert_image_dtype(im1, tf.float32)im2 = tf.image.convert_image_dtype(im2, tf.float32)ssim2 = tf.image.ssim(im1, im2, max_val=1.0)# ssim1 and ssim2 both have type tf.float32 and are almost equal.img1: First image batch.img2: Second image batch.max_val: The dynamic range of the images (i.e., the difference between themaximum the and minimum allowed values).Returns:A tensor containing an SSIM value for each image in batch.  Returned SSIMvalues are in range (-1, 1], when pixel values are non-negative. Returnsa tensor with shape: broadcast(img1.shape[:-3], img2.shape[:-3])."""_, _, checks = _verify_compatible_image_shapes(img1, img2)with ops.control_dependencies(checks):img1 = array_ops.identity(img1)# Need to convert the images to float32.  Scale max_val accordingly so that# SSIM is computed correctly.max_val = math_ops.cast(max_val, img1.dtype)max_val = convert_image_dtype(max_val, dtypes.float32)img1 = convert_image_dtype(img1, dtypes.float32)img2 = convert_image_dtype(img2, dtypes.float32)ssim_per_channel, _ = _ssim_per_channel(img1, img2, max_val)# Compute average over color channels.return math_ops.reduce_mean(ssim_per_channel, [-1])

参考:https://en.wikipedia.org/wiki/Structural_similarity

SSIM(结构相似性)-数学公式及python实现相关推荐

  1. ssim算法计算图片_图像质量评估算法 SSIM(结构相似性)

    SSIM的全称为structural similarity index,即为结构相似性,是一种衡量两幅图像相似度的指标.该指标首先由德州大学奥斯丁分校的图像和视频工程实验室(Laboratory fo ...

  2. matlab snr mse,MATLAB 均方根误差MSE、两图像的信噪比SNR、峰值信噪比PSNR、结构相似性SSIM...

    今天的作业是求两幅图像的MSE.SNR.PSNR.SSIM.代码如下: clc; close all; X = imread('q1.tif');% 读取图像 Y=imread('q2.tif'); ...

  3. 【图像处理】——图像质量评价指标信噪比(PSNR)和结构相似性(SSIM)(含原理和Python代码)

    目录 一.信噪比(PSNR) 1.信噪比的原理与计算公式 2.Python常规代码实现PSNR计算 3.TensorFlow实现PSNR计算 4.skimage实现PSNR计算 5.三种方法计算的结果 ...

  4. SSIM(structural similarity index),结构相似性

    ssim算法原理 - 我们都不是神的孩子 - CSDN博客 http://blog.csdn.net/ecnu18918079120/article/details/60149864 一.结构相似性( ...

  5. 两种常用的全参考图像质量评价指标——峰值信噪比(PSNR)和结构相似性(SSIM)

    原文:https://blog.csdn.net/zjyruobing/article/details/49908979 1.PSNR(Peak Signal to Noise Ratio)峰值信噪比 ...

  6. 图像增强评价指标学习之——结构相似性SSIM

    SSIM(structural similarity index),结构相似性,是一种衡量两幅图像相似度的指标.该指标首先由德州大学奥斯丁分校的图像和视频工程实验室(Laboratory for Im ...

  7. 图像的评价指标之SSMI——结构相似性

    图像的评价指标之SSMI--结构相似性 文章目录: https://blog.csdn.net/chaipp0607/article/details/70158835 https://zhuanlan ...

  8. ML之SSIM:基于输入图片RGB的三维向量利用SSIM(结构相似性度量)算法进行判别

    ML之SSIM:基于输入图片RGB的三维向量利用SSIM(结构相似性度量)算法进行判别 目录 输出结果 代码实现 相关文章 ML之相似度计算:图像数据.字符串数据等计算相似度常用的十种方法简介.代码实 ...

  9. 源程序的相似性分析 —— 基于Python实现哈希表

    一.问题描述 对于两个C++语言的源程序代码,用哈希表的方法分别统计两个程序中使用C++语言关键字的情况,并最终按定量的计算结果,得出两份程序的相似性. 二.需求分析 建立C++语言关键字的哈希表,统 ...

  10. python中ifelifelse用在什么结构_详解Python if-elif-else知识点

    有的时候,一个 if - else - 还不够用.比如,根据年龄的划分:条件1:18岁或以上:adult 条件2:6岁或以上:teenager 条件3:6岁以下:kid Python if-elif- ...

最新文章

  1. onsubmit校验表单时利用ajax的return false无效解决方法
  2. Winform中设置ZedGraph鼠标双击获取距离最近曲线上的点的坐标值
  3. 复旦大学邱锡鹏教授:NLP预训练模型综述
  4. zabbix邮件发不出去
  5. CNN训练模型 花卉
  6. Python笔记-方差分析之多因素方差分析
  7. 洛谷 P2437 蜜蜂路线
  8. 電郵泛濫成災 電話再成新寵
  9. Linux服务器的那些性能参数指标
  10. 11. jQuery - Chaining
  11. Linq 查询结果 可能遵循 2 º,2¹,2 ²,......增长计算
  12. 模拟集成电路设计(拉扎维)第三章学习笔记
  13. 小程序毕设日志.2021.3.13
  14. Ubuntun 18.04 NVIDIA显卡驱动安装
  15. 2020最后一天,一起回顾这不平凡的一年...
  16. Combining Word and Entity Embeddings for Entity Linking
  17. 鸿蒙3.0 APP混合开发闪退问题笔记
  18. 【数据结构和算法】赫夫曼树 | 实战演练(二)
  19. 关于virtualbox虚拟电脑控制台严重错误解决方法。。。
  20. 《用户至上:用户研究方法与实践(原书第2版)》一2.1 概述

热门文章

  1. Windows快捷键使用和打开CMD的方式
  2. deepin Linux虚拟输入法,输入法 - deepin Wiki
  3. QQ拼音输入法词库和搜狗输入法词库[相互导入](使用Excel公式)
  4. 【面试指南】如何看待你的竞争对手30k,而你却3k?想要高薪,我们也要学会拧螺丝、造飞机的能力
  5. roseha-mirror oracle数据库同步 可靠性,RoseHA集群:RHEL+RoseMirror+Oracle【1】
  6. 数据库学习总结与心得
  7. 反激式开关电源理论与原理解析
  8. c语言编程学习宝典,C语言学习宝典
  9. TeamTalk 线程池详解
  10. Postman下载与安装操作步骤【超详细】