基于交叉双边滤波和像素显著性进行图像融合的原理可参照原始论文(https://sci-hub.se/10.1007/s11760-013-0556-9)或者知乎上的一篇文章(https://www.sogou.com/link?url=hedJjaC291OfPyaFZYFLI4KQWvqt63NB2DKvsrt7Dk6d2HCun2wYzA..)。其主要的思想就是对前景区域实施更强力的模糊而对背景区域实施更小幅度的模糊,从而更好地提取出前景纹理。然后对各前景纹理进行处理(根据窗口内水平/垂直纹理的一致性计算显著性,通过协方差矩阵的特征值之和评估)获得权重图像,然后对各源图像进行像素级加权平均获得融合图像。交叉双边滤波即是为了对前景区域实施更强力的模糊而对背景区域实施更小幅度的模糊,其作用效果示意图如下:
这很好解释,因为对A的聚焦区域进行滤波时,值域滤波核取自B,而该区域在B中是失焦区域,故而值域滤波核更接近于均值滤波核,空域滤波核与值域滤波核联合的结果更接近于高斯滤波核,而对于A的失焦区域,值域滤波核衰减更快,联合滤波的滤波效果也更加轻微。
下面给出个人实现的基于交叉双边滤波与像素显著性的图像融合的MatLab程序及处理效果示例(用于图像融合的数据集可从博客https://blog.csdn.net/shitao99/article/details/83994908 提供的网址下载,suptitle.m可从https://github.com/aludnam/MATLAB/blob/master/ploting/suptitle.m下载):
clc;
close all;
% clear all;
img1=double(imread('multifocus/a01_1.tif'))/255;
img2=double(imread('multifocus/a01_2.tif'))/255;
r=5;
sigmaS=1.8;
sigmaV=25;
b1=CBF(img2,img1,r,sigmaS,sigmaV);
b2=CBF(img1,img2,r,sigmaS,sigmaV);
d1=img1-b1;
d2=img2-b2;
figure,suptitle('original & base & detail')
subplot(2,3,1),imshow(img1);
subplot(2,3,2),imshow(b1);
subplot(2,3,3),imshow(d1+0.5);
subplot(2,3,4),imshow(img2);
subplot(2,3,5),imshow(b2);
subplot(2,3,6),imshow(d2+0.5);
wr=2;
W1=WBDS(d1,wr);
W2=WBDS(d2,wr);
fused=(W1.*img1+W2.*img2)./(W1+W2);
figure,
subplot(1,2,1),imshow(W1./(W1+W2));title('weight image1');
subplot(1,2,2),imshow(W2./(W1+W2));title('weight image2');
figure,suptitle('fused image');imshow(fused);
function fimg=CBF(img,ref,r,simgaS,sigmaV)
if ~exist('r','var')
r=5;
end
if ~exist('sigmaS','var')
sigmaS=1.8;
end
if ~exist('sigmaV','var')
sigmaV=25;
end
fimg=zeros(size(img));
pimg=padarray(img,[r,r],'replicate','both');
pref=padarray(ref,[r,r],'replicate','both');
[M,N]=size(pimg);
Ws=zeros(2*r+1,2*r+1);
for i=-r:r
for j=-r:r
Ws(i+r+1,j+r+1)=exp(-(i^2+j^2)/(2*sigmaS^2));
end
end
for i=r+1:M-r
for j=r+1:N-r
block=pimg(i-r:i+r,j-r:j+r);
refBlock=pref(i-r:i+r,j-r:j+r);
refV=pref(i,j);
Wv=exp((refBlock-refV).^2/(2*sigmaV^2));
W=Ws.*Wv;
W=W/sum(W(:));
fimg(i-r,j-r)=sum(sum(W.*block));
end
end
function W=WBDS(D,r)
% Weight Based Detail Strength
pD=padarray(D,[r,r],'replicate','both');
[M,N]=size(pD);
for i=r+1:M-r
for j=r+1:N-r
block=pD(i-r:i+r,j-r:j+r);
[~,lambda1]=eig(cov(block));
[~,lambda2]=eig(cov(block'));
W(i-r,j-r)=sum(diag(lambda1))+sum(diag(lambda2));
end
end
原图、基底层图像、前景图像:
权重图像:
融合结果: