MATLAB implementation of the fast bilateral filter described in the following papers:
 K.N. Chaudhury, D. Sage, and M. Unser, "Fast O(1) bilateral filtering using trigonometric range kernels," IEEE Trans. Image Processing, vol. 20, no. 11, pp. 3376-3382, 2011.
 K.N. Chaudhury, "Acceleration of the shiftable O(1) algorithm for bilateral filtering and non-local means," IEEE Transactions on Image Processing, vol. 22, no. 4, pp. 1291-1300, 2013.
 S. Ghosh and K.N. Chaudhury, "On fast bilateral filtering using Fourier kernels," IEEE Signal Processing Letters, vol. 23, no. 5, pp. 570-573, 2016.
tank u for the code.good,keep it up.5 star for giving the code.
Hannah Winnes: In [0,255].
Are you requiring images to have value in [0,1] or in [0,255]?
Hannah Winnes: sigmar is on a scale of [0,255] and not on a scale of [0,1]. On a scale of [0,255], the filter essentially does nothing if sigmar less than 10.
This implementation works only for large values of sigmar. (In my case for sigma >= 0.27.)
I chose an image with 256x256 pixels, set sigmas = 2 and sigmar = 0.2 and got the following error message:
"Undefined function or variable "c".
Error in BilateralFast (line 53)
L = length(c);"
Andre Filipe: Yes, one can easily adapt the present code for cross bilateral filtering.
is it possible to adapt this code to get the smoothing of image A, while preserving the edges of image B (instead of smoothing A, while preserving the edges of A)? Thanks
Mikkel Gammelgaard: The code will not work on a point cloud, but could be extended to do that if there is a fast algorithm for performing smoothing on the point cloud. The whole filtering can be decomposed into a series of such smoothing operations.
Before trying, would this code work for a point cloud of xyz?
Prabhakaran Sengodan: Please see my comments from Nov 19/20.
Thanks for such a nice code. Working well for my purpose. Is the maxfilter function really needed? Is there any simple technique to approximately estimate T value? What will be the effect if I keep T as a constant(Say T = max(inputImage(:)); ). Advance thanks :)
Ben: Yes, you can modify the code for volume data as well. The dimension of the data is immaterial.
A quick question before trying it: does the code support 3D image?
Yes, it can introduce artifacts in the output if the actual T is much larger than 255. This could well be the case near edges
when processing images corrupted by noise
with large sigma. A better guess in this case would be T + C(sigma), where C(sigma) is a reasonable upper bound on the intensity variation induced by noise.
Does setting T to max (255 in my case) decrease the accuracy of the final result?
One can always use a good guess of the local dynamic range. The 'maxfilter' is not required in this case. Note, however, that the local dynamic range can be much smaller than 255(the global gynamic range) for a grayscale image, and in some cases, it might be difficult to make a good guess of T (eg, if there's a lot of noise).
Most of the time is spent on maxfilter for large image sizes. Is it really necessary, or can we just set T=255?
Thanks Derek. Bug fixed.
Thanks! One bug: change line 66 in maxFilter.m to
R(m - k + 1) = max( R(m - k + 2), template(m - k + 1, jj));
otherwise will get error if width<height
Snapshot of the GUI added.
a bug in the maxFilter code was fixed (thanks to Pravin Nair).
new version: optimized to work with narrow range kernels.
some minor fix.
Sterling's formula used to approximate the factorial computation. As a result, the filter can now be used with small range bandwidth, e.g., at \sigma_r=1.
Small fixes made to speedup the code.
Replaced rand( ) by randn( ) in the file *demo*.
Replaced 'parfor' loop with 'for' loop.
A minor update.
Code for joint filtering of multiband images added (Courtsey of Derek).
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.