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

本文为转载,原博客地址为:http://blog.csdn.net/majinlei121/article/details/50458218

"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实现的代码。
[cpp]  view plain  copy
  1. clear all;  
  2.   
  3. g = double(imread('tulips.png'))/255.0;  
  4. [m, n, d]=size(g);  
  5. if(size(g,3)==3)   
  6.     g=rgb2gray(g);   
  7. end  
  8.   
  9. %% weight 1  
  10. % epsilon=(0.001*(max(g(:))-min(g(:))))^2;  
  11. % r=1;  
  12. %   
  13. % N = boxfilter(ones(m, n), r); % the size of each local patch; N=(2r+1)^2 except for boundary pixels.  
  14. % mean_I = boxfilter(g, r) ./ N;  
  15. % mean_II = boxfilter(g.*g, r) ./ N;  
  16. % var_I = mean_II - mean_I .* mean_I;  
  17. %   
  18. % weight1=(var_I+epsilon)/(mean(var_I(:))+epsilon);         
  19.   
  20. %% weight 2  
  21. epsilon=(0.001*(max(g(:))-min(g(:))))^2;  
  22. r1=1;  
  23. r2=16;  
  24.   
  25. N1 = boxfilter(ones(m, n), r1); % the size of each local patch; N=(2r+1)^2 except for boundary pixels.  
  26. mean_I1 = boxfilter(g, r1) ./ N1;  
  27. mean_II1 = boxfilter(g.*g, r1) ./ N1;  
  28. var_I1 = mean_II1 - mean_I1 .* mean_I1;  
  29. N2 = boxfilter(ones(m, n), r2); % the size of each local patch; N=(2r+1)^2 except for boundary pixels.  
  30. mean_I2 = boxfilter(g, r2) ./ N2;  
  31. mean_II2 = boxfilter(g.*g, r2) ./ N2;  
  32. var_I2 = mean_II2 - mean_I2 .*mean_I2;  
  33.   
  34. chi_I=sqrt(abs(var_I1.*var_I2));  
  35. weight1=(var_I1+epsilon)/(mean(var_I1(:))+epsilon);         
  36. weight2=(chi_I+epsilon)/(mean(chi_I(:))+epsilon);       
  37. weight1=mat2gray(weight1);  
  38. weight2=mat2gray(weight2);  
  39.   
  40. figure;imshow(weight1);  
  41. colormap('pink');  
  42. figure;imshow(weight2);  
  43. colormap('pink');  

下面是效果:


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