├── SideWindowBoxFilter.jpg ├── README.md └── SideWindowBoxFilter.m /SideWindowBoxFilter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuanhaoGong/SideWindowFilter/HEAD/SideWindowBoxFilter.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Side Window Filtering (CVPR2019 oral, #5176) 2 | 3 | Side Window Box Filter is online. This code is implemented by Yuanhao Gong. 4 | 5 | ## Side Window Box Filter 6 | A typical example to show the side window filter is the side window box filter. The original box filter does not preserve edges. But with side window technique, side window box filter can preserve edges and corners, as shown in following figure. The MATLAB code is provided. 7 | ![image](SideWindowBoxFilter.jpg) 8 | 9 | ```text 10 | @ARTICLE{gong:cf, 11 | author={Yuanhao Gong and Ivo F. Sbalzarini}, 12 | journal={IEEE Transactions on Image Processing}, 13 | title={Curvature filters efficiently reduce certain variational energies}, 14 | year={2017}, 15 | volume={26}, 16 | number={4}, 17 | pages={1786-1798}, 18 | doi={10.1109/TIP.2017.2658954}, 19 | ISSN={1057-7149}, 20 | month={April},} 21 | 22 | @INPROCEEDINGS{gong:swf, 23 | author={Y. {Gong} and B. {Liu} and X. {Hou} and G. {Qiu}}, 24 | booktitle={2018 IEEE Visual Communications and Image Processing (VCIP)}, 25 | title={Sub-window Box Filter}, 26 | year={2018}, 27 | pages={1-4}, 28 | doi={10.1109/VCIP.2018.8698682}, 29 | ISSN={1018-8770}, 30 | month={Dec},} 31 | 32 | @inproceedings{swfilter, 33 | author={Hui Yin and Yuanhao Gong and Guoping Qiu}, 34 | Booktitle = {CVPR}, 35 | title={Side Window Filtering}, 36 | year={2019}, } 37 | ``` 38 | -------------------------------------------------------------------------------- /SideWindowBoxFilter.m: -------------------------------------------------------------------------------- 1 | function result=SideWindowBoxFilter(im, radius, iteration) 2 | %papers: 1) Sub-window Box Filter, Y.Gong, B.Liu, X.Hou, G.Qiu, VCIP2018, Dec.09, Taiwan 3 | % 2) Side Window Filtering, H.Yin, Y.Gong, G.Qiu. CVPR2019 4 | %implemented by Yuanhao Gong 5 | 6 | r = radius; %the radius of the side window 7 | k = ones(2*r+1,1)/(2*r+1); %separable kernel 8 | k_L=k; k_L(r+2:end)=0; k_L = k_L/sum(k_L); %half kernel 9 | k_R=flipud(k_L); 10 | m = size(im,1)+2*r; n = size(im,2)+2*r; total = m*n; 11 | [row, col]=ndgrid(1:m,1:n); 12 | offset = row + m*(col-1) - total; 13 | im = single(im); 14 | result = im; 15 | d = zeros(m,n,8,'single'); 16 | 17 | for ch=1:size(im,3) 18 | U = padarray(im(:,:,ch),[r,r],'replicate'); 19 | for i = 1:iteration 20 | %all projection distances 21 | d(:,:,1) = conv2(k_L, k_L, U,'same') - U; 22 | d(:,:,2) = conv2(k_L, k_R, U,'same') - U; 23 | d(:,:,3) = conv2(k_R, k_L, U,'same') - U; 24 | d(:,:,4) = conv2(k_R, k_R, U,'same') - U; 25 | d(:,:,5) = conv2(k_L, k, U,'same') - U; 26 | d(:,:,6) = conv2(k_R, k, U,'same') - U; 27 | d(:,:,7) = conv2(k, k_L, U,'same') - U; 28 | d(:,:,8) = conv2(k, k_R, U,'same') - U; 29 | 30 | %find the minimal signed distance 31 | tmp = abs(d); 32 | [~,ind] = min(tmp,[],3); 33 | index = offset+total*ind; 34 | dm = d(index); %signed minimal distance 35 | %update 36 | U = U + dm; 37 | end 38 | result(:,:,ch) = U(r+1:end-r,r+1:end-r); 39 | end 40 | --------------------------------------------------------------------------------