一、评价指标分类
对于融合图像,其评价指标可以按如下划分为三类
1 基于无参考的统计特征
2 基于有参考的理想(目标)图像
3 基于有参考的源图像
二 基于无参考的统计特征
2.1 平均梯度算法
function outval=ftidu(img)
A=double(img);
[r,c]=size(A);
[dzdx,dzdy]=gradient(A);
%分别求X的梯度和Y的梯度
s=sqrt((dzdx.^2+dzdy.^2)./2);
g=sum(sum(s))/(r*c);
outval=mean(g);
end
1.2 空间频率
function y=fSF(A)
A=double(A);
[rows,cols]=size(A);
tempA=0;tempB=0;
for i=1:rows
for j=2:cols
temp=(A(i,j)-A(i,j-1))^2;
tempA=tempA+temp;
end
end
for j=1:rows
for i=2:cols
temp=(A(i,j)-A(i-1,j))^2;
tempA=tempA+temp;
end
end
RF=(1/(rows*cols))*tempA;
CF=(1/(rows*cols))*tempB;
y=(RF+CF)^0.5;
end
2.3 信息熵
function varargout= fshang(varargin)
%函数功能:
% 函数msg求出输入图像的熵
%----------------------------------%
if nargin<1 %判断输入变量的个数
error('输入参数必须大于等于1.');
elseif nargin==1
varargout{1}=f(varargin{1});
end
end
function y= f(x)
x=uint8(x);
temp=unique(x); %temp就是x中全部不同的元素,例如x=[1,1,3,4,1,5];那么temp=[1;3;4;5]
temp=temp';
len=length(temp); %求出x矩阵中不同元素的个数
p=zeros(1,len); %p向量用来存储矩阵x中每个不同元素的个数
[m,n]=size(x);
for k=1:len
for i=1:m
for j=1:n
if x(i,j)==temp(1,k)
p(1,k)=p(1,k)+1;
end
end
end
end
for k=1:len
p(1,k)=p(1,k)/(m*n); %求出每个不同元素出现的频率
p(1,k)=-p(1,k)*log2(p(1,k));
end
y=sum(p);
end
三 基于有参考的理想(目标)图像
3.1 均方根误差
function varargout= fjunfang(varargin)
if nargin<2
error('输入参数必须大于等于2.');
elseif nargin==2
varargout{1}=h(varargin{1},varargin{2});
end
end
function r=h(f,g)
f=double(f);
g=double(g);
[m,n]=size(f);
temp=[];
for i=1:m
for j=1:n
temp(i,j)=(f(i,j)-g(i,j))^2;
end
end
r=sqrt(sum(sum(temp))/(m*n));
end
3.2 峰值信噪比
function varargout= fSNR(varargin)
if nargin<2
error('输入参数必须大于等于2.');
elseif nargin==2
varargout{1}=h(varargin{1},varargin{2});
end
end
function r=h(f,g)
f=double(f);
g=double(g);
[m,n]=size(f);
temp=[];
for i=1:m
for j=1:n
temp(i,j)=(f(i,j)-g(i,j))^2;
end
end
r=sqrt(sum(sum(temp))/(m*n));
3.3 相关系数
function coeff = myPearson(X , Y)
if length(X) ~= length(Y)
error('两个数值数列的维数不相等');
return;
end
fenzi = sum(X .* Y) - (sum(X) * sum(Y)) / length(X);
fenmu = sqrt((sum(X .^2) - sum(X)^2 / length(X)) * (sum(Y .^2) - sum(Y)^2 / length(X)));
coeff = fenzi / fenmu;
end %函数myPearson结束
四 基于有参考的源图像
4.1 交叉熵
clc;clear;close all;
A=imread('test2.jpg');B=imread('1.tif');C=imread('2.tif');
[m,n]=size(A);
a=zeros(1,256);
for i=1:m
for j=1:n
a(1,A(i,j)+1)=a(1,A(i,j)+1)+1;
end
end
b=zeros(1,256);
for i=1:m
for j=1:n
b(1,B(i,j)+1)=b(1,B(i,j)+1)+1;
end
end
c=zeros(1,256);
for i=1:m
for j=1:n
c(1,C(i,j)+1)=c(1,C(i,j)+1)+1;
end
end
%_____________________________________________________%
a=double(a);b=double(b);c=double(c);
a=a/(m*n);b=b/(m*n);c=c/(m*n);
cen1=0;
for i=1:256
if a(1,i)==0
temp3=0;
else
temp1=b(1,i)/a(1,i);
temp2=log2(temp1);
if temp2==-Inf
temp2=0;
end
temp3=b(1,i)*temp2;
end
cen1=cen1+temp3;
end
cen2=0;
for i=1:256
if a(1,i)==0
temp3=0;
else
temp1=c(1,i)/a(1,i);
temp2=log2(temp1);
if temp2==-Inf
temp2=0;
end
temp3=c(1,i)*temp2;
end
cen2=cen2+temp3;
end
cen=(cen1*cen1+cen2*cen2)/2;
cen=sqrt(cen);
fprintf('\n交叉熵为:%f\n',cen);
4.2 边缘信息保持度
I=imread('');
I2=imread(''); % 分别表示原始图像,和处理后图像
imU=I(1:end-1, :);
imD=I(2:end, :); % 上部,下部
imL=I(:, 1:end-1);
imR=I(:, 2:end); % 左部,右部;
im2U=I2(1:end-1, :);
im2D=I2(2:end, :); % 上部,下部
im2L=I2(:, 1:end-1);
im2R=I2(:, 2:end);
EPI_H = sum(sum(abs(imR - imL)))/sum(sum(abs(im2R - im2L)));
EPI_V = sum(sum(abs(imU - imD)))/sum(sum(abs(im2D - im2D)));
fprint('水平保持度为%f\n,竖直保持度为%f\n',EPI_H,EPI_V)
3.3 结构相似度
clc;
clear;
im1=imread('1.jpg');
im2=imread('2.jpg');
img1=double(im1);
img2=double(im2);
[mssim,ssim_map] = ssim(img1, img2);
fin=mssim
function [mssim, ssim_map] = ssim(img1, img2, K, window, L)
%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:
% size(img1) - size(window) + 1.
%
%Default Usage:
% Given 2 test images img1 and img2, whose dynamic range is 0-255
%
% [mssim ssim_map] = ssim_index(img1, img2);
%
%Advanced Usage:
% User defined parameters. For example
%
% K = [0.05 0.05];
% window = ones(8);
% L = 100;
% [mssim ssim_map] = ssim_index(img1, img2, K, window, L);
%
%See the results:
%
% mssim %Gives the mssim value
% imshow(max(0, ssim_map).^4) %Shows the SSIM index map
%
%========================================================================
if (nargin < 2 || nargin > 5)
% ssim_index = -Inf;
ssim_map = -Inf;
return;
end
if (size(img1) ~= size(img2))
% ssim_index = -Inf;
ssim_map = -Inf;
return;
end
[M N] = size(img1);
if (nargin == 2)
if ((M < 11) || (N < 11)) % 图像大小过小,则没有意义。
% ssim_index = -Inf;
ssim_map = -Inf;
return
end
window = fspecial('gaussian', 11, 1.5); % 参数一个标准偏差1.5,11*11的高斯低通滤波。
K(1) = 0.01; % default settings
K(2) = 0.03; %
L = 255; %
end
if (nargin == 3)
if ((M < 11) || (N < 11))
% ssim_index = -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)
% ssim_index = -Inf;
ssim_map = -Inf;
return;
end
else
% ssim_index = -Inf;
ssim_map = -Inf;
return;
end
end
if (nargin == 4)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
% ssim_index = -Inf;
ssim_map = -Inf;
return
end
L = 255;
if (length(K) == 2)
if (K(1) < 0 || K(2) < 0)
% ssim_index = -Inf;
ssim_map = -Inf;
return;
end
else
% ssim_index = -Inf;
ssim_map = -Inf;
return;
end
end
if (nargin == 5)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
% ssim_index = -Inf;
ssim_map = -Inf;
return
end
if (length(K) == 2)
if (K(1) < 0 || K(2) < 0)
% ssim_index = -Inf;
ssim_map = -Inf;
return;
end
else
% ssim_index = -Inf;
ssim_map = -Inf;
return;
end
end
%%
C1 = (K(1)*L)^2; % 计算C1参数,给亮度L(x,y)用。
C2 = (K(2)*L)^2; % 计算C2参数,给对比度C(x,y)用。
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; % 计算出Ux平方值。
mu2_sq = mu2.*mu2; % 计算出Uy平方值。
mu1_mu2 = mu1.*mu2; % 计算Ux*Uy值。
sigma1_sq = filter2(window, img1.*img1, 'valid') - mu1_sq; % 计算sigmax (标准差)
sigma2_sq = filter2(window, img2.*img2, 'valid') - mu2_sq; % 计算sigmay (标准差)
sigma12 = filter2(window, img1.*img2, 'valid') - mu1_mu2; % 计算sigmaxy(标准差)
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
end
四、备注
完整代码或者代写添加QQ 1564658423