This is the MATLAB implementation of the fast approximation of the bilateral filter (for 8-bit grayscale
images) described in the following article:
 K. N. Chaudhury, S. Dabhade, ''Fast and provably accurate bilateral filtering'', IEEE Transactions on Image Processing, vol 26, no. 5, pp. 2519-2528, 2016. (arXiv: http://arxiv.org/abs/1603.08109)
Kunal Chaudhury (2021). Fast and Accurate Bilateral Filtering (https://www.mathworks.com/matlabcentral/fileexchange/56158-fast-and-accurate-bilateral-filtering), MATLAB Central File Exchange. Retrieved .
Thank you Kunal for the original implementation and to Ian for this helpful suggestion to use separable filters. I tried it and although it saves "only" about 10-30% small values of spatial sigma, there are substantial savings for sigma > 10 pixels, roughly a factor of N where N = sigma/10. Perhaps even more importantly, it cuts dependencies on unnecessary toolboxes, which is very helpful for me.
Ian's notation doesn't work as is, but here is the updated version with his idea:
(perhaps these changes will make it into the next release)
Ian Craig: I tried what you suggested, but the timing didn't change significantly!
Nice. If I have to extend this to 12-bit or 16-bit grey-scale images. What do I have to change in the existing code?
Very nice. I have one suggestion, though. You can take advantage of the fact that both the Gaussian and box kernels are rank 1 and use `conv(Hs, Hs, im, 'same')` instead of using `padarray` and `imfilter`. In this case, `Hs` would be the one-dimensional version of your filter. For box, it would be `Hs = ones(2*L + 1, 1)/(2*L + 1);` and for Gaussian it would be `Hs = exp(-((L:L).^2/(2*sigmar^2))/(sigmar * sqrt(2*pi));` (a normalized Gaussian). Your operations for each filter step goes way down, you don't have to do the last step where you extract the image from the center of the padding, and you remove the dependency on the Image Processing Toolbox.
May I ask how can I get one image instead of 3 images in the output?
Hi Kunal. Excellent submission. There are a few bugs however. It's always the safest to implement your code by assuming your input is normalized between 0 to 1. Increasing the spatial Gaussian sigma, i.e, the size of the filter, causes your data to be "suppressed".
You should also consider providing example operational parameters. Many newbies to IP prefer it if the authors provide a rough range of parameters to play with.
Would this approach extend to RGB images?
Making this change will allow the algorithm to process three planes:
g= T+sigmar*(P(L+1:end-L,L+1:end-L,:) ...
However, I am not yet sure how to use the Euclidean distance (I plan to work in the L*a*b space). Continuing to work through the formulations in the paper to see if its easily extensible.
hi sir,i need to find the mean sq error(MSE),PSNR, normalised absolute error & histogram of the image for both BOX & gaussian filter.If u have no problem in sharing these codes.I REQUEST you to kindly share it.so, that it will we be helpfull for me.waiting for your reply.
Thanks for the code
Thanks for your code!
Thanks for the code. I appreciate your hard work!! its easy to understand and use.
Very nice! thanks for sharing
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!