当前位置:网站首页>Learning of image enhancement evaluation index -- structural similarity SSIM
Learning of image enhancement evaluation index -- structural similarity SSIM
2022-07-28 05:31:00 【qq_ forty-six million one hundred and sixty-five thousand eight】
SSIM(structural similarity index), Structural similarity , It's a measure of the similarity between two images . The index was first developed by the image and video Engineering Laboratory of the University of Texas at Austin (Laboratory for Image and Video Engineering) Put forward .SSIM Of the two images used , An uncompressed, undistorted image , The other is the distorted image .
As the realization of structural similarity theory , The structure similarity index defines the structure information as unique to brightness from the perspective of image composition 、 Contrast , Attributes that reflect the structure of objects in the scene , The distortion is modeled as brightness 、 A combination of three different factors of contrast and structure . The mean value is used as the estimation of brightness , The standard deviation is used as an estimate of contrast , Covariance as a measure of structural similarity .
The above is the explanation of Baidu Encyclopedia , There are also encyclopedias of corresponding formulas .
SSIM It belongs to the full reference image quality evaluation index . It's very embarrassing that at first I always took the reference image as the original .
Then a want to , Theoretically SSIM The closer it is to 1 The better i, But if you use the original low illumination image , No processing yes 1, The more processing, the lower , This is definitely wrong , I took a detailed look at the comments on people's official code .
Originally, this reference image refers to a picture that is considered perfect , It means doing image enhancement , We need a set of images in the database , A low illumination image that needs to be processed and a perfect normal image , Then we use the processed image and the perfect image to calculate .
The code and usage are shared with you , What if some beginners make a mistake .
function [mssim, ssim_map] = ssim(img1, img2, K, window, L)
if (nargin < 2 || nargin > 5)
mssim = -Inf;
ssim_map = -Inf;
return;
end
if (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;
return
end
window = fspecial('gaussian', 11, 1.5); %
K(1) = 0.01; % default settings
K(2) = 0.03; %
L = 255; %
end
if (nargin == 3)
if ((M < 11) || (N < 11))
mssim = -Inf;
ssim_map = -Inf;
return
end
window = fspecial('gaussian', 11, 1.5);
L = 255;
if (length(K) == 2)
if (K(1) < 0 || K(2) < 0)
mssim = -Inf;
ssim_map = -Inf;
return;
end
else
mssim = -Inf;
ssim_map = -Inf;
return;
end
end
if (nargin == 4)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mssim = -Inf;
ssim_map = -Inf;
return
end
L = 255;
if (length(K) == 2)
if (K(1) < 0 || K(2) < 0)
mssim = -Inf;
ssim_map = -Inf;
return;
end
else
mssim = -Inf;
ssim_map = -Inf;
return;
end
end
if (nargin == 5)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mssim = -Inf;
ssim_map = -Inf;
return
end
if (length(K) == 2)
if (K(1) < 0 || K(2) < 0)
mssim = -Inf;
ssim_map = -Inf;
return;
end
else
mssim = -Inf;
ssim_map = -Inf;
return;
end
end
img1 = 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);
end
C1 = (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));
else
numerator1 = 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);
returnThis is the calculation SSIM The subroutine of .
About its use , Just write the following code directly into the main program .
K = [0.05 0.05];
window = ones(8);
L = 100;
[mssim, ssim_map] = ssim(img1, img2, K, window, L);
mssim The official annotation :
input:(1) img1: The first image being compared
(2) img2: The second image being compared
(3) K:SSIM Constant in exponential formula . The default value is :K = [0.01 0.03]
(4) window: Local statistics window . Default widnow Gauss , Given by the following formula
window = fspecial('gaussian ',11,1.5);
(5) L: The dynamic range of the image . The default value is :L = 255
output:(1) mssim: Average between two images ssim Index value .
If one of the images being compared is considered to be of perfect quality , that mssim It can be considered as another measure of image quality .
If img1 = img2, be mssim = 1.
(2) ssim_map: Test the image of ssim Index diagram .
map The size of depends on the input image , The actual size depends on the window size and the down sampling factor .边栏推荐
- repackag failed: Unable to find main class
- 接口幂等性问题
- First acquaintance with C language (1)
- 动态卷积的本质
- PC端-bug记录
- 2022 summer practice (PowerDesigner tutorial learning record) (first week)
- 测试开发---自动化测试中的UI测试
- 深度学习热力图可视化的方式
- Scanf function of input and output function in C language
- Example of main diagram of paper model
猜你喜欢

SSLError

【SLAM】LVI-SAM解析——综述

蒙特卡罗方法求解圆周率π并用turtle画点,以及完成进度条问题

ES6 new variable modifiers let and const, new basic data type symbol

Digital twin solutions inject new momentum into the construction of chemical parks

ECCV22 最新54篇论文主图整理

2022 summer practice (PowerDesigner tutorial learning record) (first week)

VMware Workstation 与 Device/Credential Guard 不兼容。禁用 Device/Credential Guard

Scope, execution process and life cycle of bean

ByteBuffer.position 抛出异常 IllegalArgumentException
随机推荐
GET与POST区别
JVM note 4: Memory Model
【MySQL】MySQL时区问题、数据库时间相差8小时问题解决
关于swagger中的localDateTime
JVM篇 笔记3:类加载与字节码技术
JMeter related knowledge sorting
First acquaintance with C language (2)
自定义Json返回数据
Classes and objects [medium]
sql 查询list时两次的数据不一致,自动加上了limit
How practical is the struct module? Learn a knowledge point immediately
When SQL queries the list, the data is inconsistent twice, and limit is automatically added
DELL远程控制卡 使用ipmitools设置ipmi
Multi module packaging: package: XXX does not exist
latex和word之间相互转换
MySQL uses list as a parameter to query
MySQL practice 45 lectures
[slam] lvi-sam analysis - Overview
MySQL basic query
Eccv2022 | 29 papers of Tencent Youtu were selected, including face security, image segmentation, target detection and other research directions