"Bilateral texture filtering"论文 matlab实现代码
2016-01-05 23:08
381 查看
根据论文"Cho H, Lee H, Kang H, et al. Bilateral texture filtering[J]. ACM Transactions on Graphics (TOG), 2014, 33(4): 128."编写。
代码如下:
下面是效果图:
代码如下:
%% Cho H, Lee H, Kang H, et al. Bilateral texture filtering[J]. %% ACM Transactions on Graphics (TOG), 2014, 33(4): 128. clear all; g = double(imread('D:\数字图像处理\研究方向\Filter Smooth\images\barbara.png'))/255.0; [m, n, c]=size(g); if(size(g,3)==3) g=rgb2gray(g); end k=7; radius=(k-1)/2; % k X k window radius g=padarray(g,[radius,radius],'symmetric'); % Pad array once [rows,cols]=size(g); for i=1:5, %% tonalRanges tonalRanges=zeros(size(g)); parfor y=radius+1:rows-radius for x=radius+1:cols-radius ymin=y-radius; ymax=y+radius; xmin=x-radius; xmax=x+radius; roi=g(ymin:ymax,xmin:xmax); tonalRanges(y,x)=max(roi(:))-min(roi(:)); % Tonal Range = Max - Min of Window end end %% mRTV mRTV=zeros(size(g)); epsilon=10^(-9); [gmag]=imgradient(g,'centralDifference'); % sqrt(x^2+y^2); parfor y=radius+1:rows-radius for x=radius+1:cols-radius ymin=y-radius; ymax=y+radius; xmin=x-radius; xmax=x+radius; window=gmag(ymin:ymax,xmin:xmax); % window stores magnitudes of roi mRTV(y,x)=max(window(:)); % Max of Magnitudes mRTV(y,x)=mRTV(y,x)/(sum(window(:))+epsilon); % relative total Variation end end mRTV=mRTV.*tonalRanges; % Multiply by DeltaP %% Patch Shift Bq=gaussFilter(g,1); G=zeros(size(Bq)); mRTVP=mRTV; mRTVQ=zeros(size(mRTVP)); parfor y=radius+1:rows-radius for x=radius+1:cols-radius window=mRTVP(y-radius:y+radius,x-radius:x+radius); [~,index]=min(window(:)); [yy,xx]=ind2sub([size(window,1),size(window,2)],index); pos=[y-radius-1,x-radius-1]; pos=pos+[yy,xx]; G(y,x)=Bq(pos(1),pos(2)); mRTVQ(y,x)=mRTVP(pos(1),pos(2)); end end Guide=G; %% Alpha sigmaAlpha = 5*k; dif=mRTVP-mRTVQ; dif=-dif*sigmaAlpha; dif=exp(dif); dif=1+dif; dif=dif.^(-1); dif=dif-0.5; alpha=2*dif; %% Gprime Gprime=double(alpha).*double(Guide)+double(1-alpha).*double(Bq); %% Guide Bilateral Filter sigma_r=sqrt(c)*0.05; sigma_d=k-1; s=2*k-1; J=bilateralFilter1(g,Gprime,0,1.0,sigma_d,sigma_r); g=J; end %% result % tonalRanges=tonalRanges(radius+1:end-radius,radius+1:end-radius); % mRTV=mRTV(radius+1:end-radius,radius+1:end-radius); % Guide=Guide(radius+1:end-radius,radius+1:end-radius); % Gprime=Gprime(radius+1:end-radius,radius+1:end-radius); J=J(radius+1:end-radius,radius+1:end-radius); % figure;imshow(tonalRanges,[]);title('TonalRange'); % colormap('default'); % figure;imshow(mRTV,[]);title('mRTV'); % colormap('default'); % figure;imshow(Guide,[]);title('Guide'); % figure;imshow(alpha,[]);title('Alpha'); % colormap('default'); % figure;imshow(Gprime,[]);title('Gprime'); figure;imshow(J,[]);title('output');其中的gaussFilter()和bilateralFilter()分别为高斯滤波函数和双边滤波函数,在以前的博文中均以列出。
下面是效果图:
相关文章推荐
- matlab中feval函数的用法
- /usr/local/MATLAB/R2013a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found 解决方法
- WPS与matlab安装后直接命令行启动设置
- 稀疏表示字典的显示(MATLAB实现代码)
- Matlab图像彩色转灰色
- matlab读入矩阵数据
- Matlab中的图形句柄(转载)
- 双边滤波(bilateral filter)快速算法 matlab实现代码
- 双边滤波(bilateral filter)彩色图 matlab实现代码
- 双边滤波(bilateral filter)灰度图 matlab实现代码
- 【Matlab】关于axes和figure对象的关系
- Matlab界面中选项卡的切换
- matlab函数 bsxfun浅谈(转载)
- matlab中parfor函数
- 说说wavedec2函数
- matlab2013b调用cpp文件,mex,VS2013配置问题
- matlab2013b 安装教程
- "Gradient Domain Guided Image Filtering"论文中边缘权重函数matlab实现代码
- Matlab 原始txt分裂为新的txt文件
- matlab显示的图片,手动保存时四周有白边