图像增强的评价标准在像素层面上通常包含有平均绝对误差法(MAE)、均方误差法(MSE)、峰值信噪比(PSNR)以及结构相似度(SSIM),目前图像增强(图像超分辨率、图像去噪、图像去模糊、图像去雨,图像去块效应等)比较权威的客观评价标准为峰值信噪比(PSNR)与结构相似度(SSIM)。下面给出峰值信噪比与结构相似度的计算公式与matlab实现方式:
PSNR与SSIM的公式
PSNR的计算公式如下:
即PSNR的计算方法是在MSE的基础上得到相应于2^
n
n
n的对数比值,
n
n
n为图像的位数,一般为8位,
M
M
M、
N
N
N位图像的宽高,
X
(
i
,
j
)
X(i, j)
X(i,j)与
X
′
(
i
,
j
)
X'(i, j)
X′(i,j)为增强后的图像与lable在位置
(
i
,
j
)
(i, j)
(i,j)的像素值。
SSIM的计算公式如下:
其中
μ
\mu
μ和
σ
\sigma
σ代表的是图像块的均值和方差,而
σ
x
y
\sigma_{xy}
σxy表示的图像块
x
x
x与图像块
y
y
y 之间的协方差,
C
1
C_1
C1和
C
2
C_2
C2为常数,一般可设置为0。
PSNR与SSIM的代码实现
PSNR的matlab代码实现:
function psnr=PSNR_Compute(im1,im2)
if size(im1, 3) == 3,
im1 = rgb2ycbcr(im1);
im1 = im1(:, :, 1);
end
if size(im2, 3) == 3,
im2 = rgb2ycbcr(im2);
im2 = im2(:, :, 1);
end
imdff = double(im1) - double(im2);
imdff = imdff(:);
rmse = sqrt(mean(imdff.^2));
psnr = 20*log10(255/rmse);
SSIM的matlab代码实现:
function ssim = cal_ssim( im1, im2, b_row, b_col )
[h w] = size( im1 );
ssim = ssim_index( im1( b_row+1:h-b_row, b_col+1:w-b_col ), im2( b_row+1:h-b_row, b_col+1:w-b_col ) );
return;
function [mssim, ssim_map] = ssim_index(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; % 默认设置
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
C1 = (K(1)*L)^2;
C2 = (K(2)*L)^2;
window = window/sum(sum(window));
img1 = double(img1);
img2 = double(img2);
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);
return