"Gradient Domain Guided Image Filtering"论文中边缘权重函数matlab实现代码

"Kou F, Chen W, Wen C, et al. Gradient Domain Guided Image Filtering[J]. Image Processing, IEEE Transactions on, 2015, 24(11): 4528-4539."论文中权重函数matlab实现的代码。
clear all;

g = double(imread('tulips.png'))/255.0;
[m, n, d]=size(g);
if(size(g,3)==3) 
    g=rgb2gray(g); 
end

%% weight 1
% epsilon=(0.001*(max(g(:))-min(g(:))))^2;
% r=1;
% 
% N = boxfilter(ones(m, n), r); % the size of each local patch; N=(2r+1)^2 except for boundary pixels.
% mean_I = boxfilter(g, r) ./ N;
% mean_II = boxfilter(g.*g, r) ./ N;
% var_I = mean_II - mean_I .* mean_I;
% 
% weight1=(var_I+epsilon)/(mean(var_I(:))+epsilon);       

%% weight 2
epsilon=(0.001*(max(g(:))-min(g(:))))^2;
r1=1;
r2=16;

N1 = boxfilter(ones(m, n), r1); % the size of each local patch; N=(2r+1)^2 except for boundary pixels.
mean_I1 = boxfilter(g, r1) ./ N1;
mean_II1 = boxfilter(g.*g, r1) ./ N1;
var_I1 = mean_II1 - mean_I1 .* mean_I1;
N2 = boxfilter(ones(m, n), r2); % the size of each local patch; N=(2r+1)^2 except for boundary pixels.
mean_I2 = boxfilter(g, r2) ./ N2;
mean_II2 = boxfilter(g.*g, r2) ./ N2;
var_I2 = mean_II2 - mean_I2 .*mean_I2;

chi_I=sqrt(abs(var_I1.*var_I2));
weight1=(var_I1+epsilon)/(mean(var_I1(:))+epsilon);       
weight2=(chi_I+epsilon)/(mean(chi_I(:))+epsilon);     
weight1=mat2gray(weight1);
weight2=mat2gray(weight2);

figure;imshow(weight1);
colormap('pink');
figure;imshow(weight2);
colormap('pink');

下面是效果:



你可能感兴趣的:(图像处理)