一、SSIM基本定义

SSIM全称为“Structural Similarity Index”,中文意思即为结构相似性,是衡量图像质量的指标之一。给定两张图像x和y,其结构相似性可以定义为:

matlab中对SSIM的文档说明:

SSIM的范围为[0,1],其值越大,表示图像的质量越好。当两张图像一模一样时,此时SSIM=1。计算SSIM有两种方法:

方法一:使用开源结构相似性函数

方法二:直接使用matlab的内置函数ssim()

matlab中对ssim()函数的文档说明:


二、matlab实现SSIM

1、方法二:SSIM.m

function [mssim, ssim_map] = SSIM(img1, img2, K, window, L)% ========================================================================
% SSIM Index with automatic downsampling, Version 1.0
% Copyright(c) 2009 Zhou Wang
% All Rights Reserved.
%
% ----------------------------------------------------------------------
% Permission to use, copy, or modify this software and its documentation
% for educational and research purposes only and without fee is hereby
% granted, provided that this copyright notice and the original authors'
% names appear on all copies and supporting documentation. This program
% shall not be used, rewritten, or adapted as the basis of a commercial
% software or hardware product without first obtaining permission of the
% authors. The authors make no representations about the suitability of
% this software for any purpose. It is provided "as is" without express
% or implied warranty.
%----------------------------------------------------------------------
%
% This is an implementation of the algorithm for calculating the
% Structural SIMilarity (SSIM) index between two images
%
% Please refer to the following paper and the website with suggested usage
%
% Z. Wang, A. C. Bovik, H. R. Sheikh, and E. P. Simoncelli, "Image
% quality assessment: From error visibility to structural similarity,"
% IEEE Transactios on Image Processing, vol. 13, no. 4, pp. 600-612,
% Apr. 2004.
%
% http://www.ece.uwaterloo.ca/~z70wang/research/ssim/
%
% Note: This program is different from ssim_index.m, where no automatic
% downsampling is performed. (downsampling was done in the above paper
% and was described as suggested usage in the above website.)
%
% Kindly report any suggestions or corrections to zhouwang@ieee.org
%
%----------------------------------------------------------------------
%
%Input : (1) img1: the first image being compared
%        (2) img2: the second image being compared
%        (3) K: constants in the SSIM index formula (see the above
%            reference). defualt value: K = [0.01 0.03]
%        (4) window: local window for statistics (see the above
%            reference). default widnow is Gaussian given by
%            window = fspecial('gaussian', 11, 1.5);
%        (5) L: dynamic range of the images. default: L = 255
%
%Output: (1) mssim: the mean SSIM index value between 2 images.
%            If one of the images being compared is regarded as
%            perfect quality, then mssim can be considered as the
%            quality measure of the other image.
%            If img1 = img2, then mssim = 1.
%        (2) ssim_map: the SSIM index map of the test image. The map
%            has a smaller size than the input images. The actual size
%            depends on the window size and the downsampling factor.
%
%Basic Usage:
%   Given 2 test images img1 and img2, whose dynamic range is 0-255
%
%   [mssim, ssim_map] = ssim(img1, img2);
%
%Advanced Usage:
%   User defined parameters. For example
%
%   K = [0.05 0.05];
%   window = ones(8);
%   L = 100;
%   [mssim, ssim_map] = ssim(img1, img2, K, window, L);
%
%Visualize the results:
%
%   mssim                        %Gives the mssim value
%   imshow(max(0, ssim_map).^4)  %Shows the SSIM index map
%========================================================================if (nargin < 2 || nargin > 5)mssim = -Inf;ssim_map = -Inf;return;
endif (size(img1) ~= size(img2))mssim = -Inf;ssim_map = -Inf;return;
end[M N] = size(img1);if (nargin == 2)if ((M < 11) || (N < 11))mssim = -Inf;ssim_map = -Inf;returnendwindow = fspecial('gaussian', 11, 1.5);  %K(1) = 0.01;                  % default settingsK(2) = 0.03;                 %L = 255;                                     %
endif (nargin == 3)if ((M < 11) || (N < 11))mssim = -Inf;ssim_map = -Inf;returnendwindow = fspecial('gaussian', 11, 1.5);L = 255;if (length(K) == 2)if (K(1) < 0 || K(2) < 0)mssim = -Inf;ssim_map = -Inf;return;endelsemssim = -Inf;ssim_map = -Inf;return;end
endif (nargin == 4)[H W] = size(window);if ((H*W) < 4 || (H > M) || (W > N))mssim = -Inf;ssim_map = -Inf;returnendL = 255;if (length(K) == 2)if (K(1) < 0 || K(2) < 0)mssim = -Inf;ssim_map = -Inf;return;endelsemssim = -Inf;ssim_map = -Inf;return;end
endif (nargin == 5)[H W] = size(window);if ((H*W) < 4 || (H > M) || (W > N))mssim = -Inf;ssim_map = -Inf;returnendif (length(K) == 2)if (K(1) < 0 || K(2) < 0)mssim = -Inf;ssim_map = -Inf;return;endelsemssim = -Inf;ssim_map = -Inf;return;end
endimg1 = double(img1);
img2 = double(img2);% automatic downsampling
f = max(1,round(min(M,N)/256));
%downsampling by f
%use a simple low-pass filter
if(f>1)lpf = ones(f,f);lpf = lpf/sum(lpf(:));img1 = imfilter(img1,lpf,'symmetric','same');img2 = imfilter(img2,lpf,'symmetric','same');img1 = img1(1:f:end,1:f:end);img2 = img2(1:f:end,1:f:end);
endC1 = (K(1)*L)^2;
C2 = (K(2)*L)^2;
window = window/sum(sum(window));mu1   = filter2(window, img1, 'valid');
mu2   = filter2(window, img2, 'valid');
mu1_sq = mu1.*mu1;
mu2_sq = mu2.*mu2;
mu1_mu2 = mu1.*mu2;
sigma1_sq = filter2(window, img1.*img1, 'valid') - mu1_sq;
sigma2_sq = filter2(window, img2.*img2, 'valid') - mu2_sq;
sigma12 = filter2(window, img1.*img2, 'valid') - mu1_mu2;if (C1 > 0 && C2 > 0)ssim_map = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))./((mu1_sq + mu2_sq + C1).*(sigma1_sq + sigma2_sq + C2));
elsenumerator1 = 2*mu1_mu2 + C1;numerator2 = 2*sigma12 + C2;denominator1 = mu1_sq + mu2_sq + C1;denominator2 = sigma1_sq + sigma2_sq + C2;ssim_map = ones(size(mu1));index = (denominator1.*denominator2 > 0);ssim_map(index) = (numerator1(index).*numerator2(index))./(denominator1(index).*denominator2(index));index = (denominator1 ~= 0) & (denominator2 == 0);ssim_map(index) = numerator1(index)./denominator1(index);
end
mssim = mean2(ssim_map);
return

2、主函数main.m

clc;clear;close all;
rgbimage=imread('boy.jpg');
attack_rgbimage=imnoise(rgbimage,'salt & pepper',0.1);
figure(1),
subplot(121),imshow(rgbimage);
title('原始图像');
subplot(122),imshow(attack_rgbimage);
title('噪声攻击图像');ssimval1=SSIM(rgbimage,attack_rgbimage);% 方法一
disp('SSIM函数的结构相似性:');
disp(ssimval1);ssimval2=ssim(rgbimage,attack_rgbimage);% 方法二
disp('matlab内置函数的结构相似性:');
disp(ssimval2);

三、实现结果分析

1、输出结果


2、结果分析

1、注意每次运行主函数main.m文件,输出的SSIM值都会有细微差别,可以对比上下两张图。

2、可以发现开源函数计算的SSIM值总比matlab内置函数计算的SSIM值大,具体原因不可知。

3、仅以椒盐噪声的参数为讨论,我们将主函数main.m文件椒盐噪声的方差改为0.01,可以与上方得到方差为0.05的SSIM结果进行对比,可以看出得到的SSIM要大很多。

参考博客:图像质量评估指标:MSE,PSNR,SSIM

图像处理之图像质量评价指标SSIM(结构相似性)相关推荐

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

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

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

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

  3. 图像处理之图像质量评价指标MSE(均方误差)

    一.MSE基本定义 MSE全称为"Mean Square Error",中文意思即为均方误差,是衡量图像质量的指标之一.计算原理为真实值与预测值的差值的平方然后求和再平均,公式如下 ...

  4. 图像处理之图像质量评价指标RMSE(均方根误差)

    一.RMSE基本定义 MSE全称为"Root Mean Square Error",中文意思即为均方根误差,是衡量图像质量的指标之一.计算原理为真实值与预测值的差值的平方然后求和再 ...

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

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

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

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

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

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

  8. 图像质量评价指标: PSNR 和 SSIM

    PSNR: Image quality assessment: from error visibility to structural similarity SSIM: Image Quality A ...

  9. 【图像相关】图像质量评价指标 PSNR 和 SSIM

    文章目录 PSNR SSIM 参考链接 PSNR PSNR 是 "Peak Signal to Noise Ratio" 的缩写,即峰值信噪比,是一种评价图像的客观标准,它具有局限 ...

  10. 图像质量评价指标PSNR和SSIM

    由于是从Word文档直接复制过来,其中格式如果乱码或者不通顺,请评论区告知我 参考链接: https://blog.csdn.net/dxpqxb/article/details/85071338 h ...

最新文章

  1. Node.js与Sails~方法拦截器policies
  2. 自然语言处理十问!独家福利
  3. Java程序员考什么证可以镀金?
  4. 在DevExpress程序中使用GridView直接录入数据的时候,增加列表选择的功能
  5. jvm性能调优实战 - 48无限循环调用和没有缓存的动态代理引起的OOM
  6. 坡道行驶电动小车_事发红绿灯路口!东莞一女子骑电动滑板车被撞致颅内出血…...
  7. tf里面InteractivateSession()与Session()的区别
  8. 4、Python运算符、比较运算符、赋值运算符、位运算符、逻辑运算符、成员运算符、身份运算符、运算符优先级(学些笔记)
  9. 六大举措建云管理模式助力企业转型升级
  10. mplayer slave 模式文档翻译
  11. EF-DbUpdateException--实体类和数据库列不对应的解决方案
  12. oracle数据库学习相关笔记-相关约束
  13. Matplotlib--legend函数
  14. 二调建设用地地类代码_最新二调土地地类代码表
  15. 学籍成绩管理系统c语言,学籍成绩管理系统UCDOS操作系统下C语言版本课程设计).doc...
  16. 计算机主机结构讲解,电脑内部结构图和讲解
  17. 如何让OpenwrtX86和win7双系统共存在一块硬盘
  18. mysql 直方图统计_MySQL 8.0 新特性之统计直方图
  19. 代理平台kb-proxy:注册与登录【三】
  20. 天黑请闭眼 杀人游戏 规则 02

热门文章

  1. mi5splus android9,小米5SPlus 安卓9.0 原生体验 LineageOS16.0 ROOT
  2. LoadRunner教程(2)-LoadRunner性能测试利器
  3. java读取修改文件内容_JAVA读取文件指定内容进行修改
  4. 如何轻松集成VARCHART XGantt
  5. 电商后台管理系统——JavaWeb项目 毕业设计论文
  6. 手动卸载McAfee
  7. 软件开发人员的简历项目经验怎么写
  8. 怎么提供专利技术交底书
  9. python信噪比signaltonoise, SNR
  10. 冯诺依曼计算机流程图,基本流程图综述