View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Fast Bilateral Filter

3.7 | 5 ratings Rate this file 39 Downloads (last 30 days) File Size: 65.1 KB File ID: #36657 Version: 2.3
image thumbnail

Fast Bilateral Filter


Kunal Chaudhury (view profile)


11 May 2012 (Updated )

Fast bilateral filtering using Fourier approximation.

| Watch this File

File Information

MATLAB implementation of the fast bilateral filter described in the following papers:
[1] 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.
[2] 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.
[2] 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.

Required Products Image Processing Toolbox
MATLAB release MATLAB 8.4 (R2014b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (22)

tank u for the code.good,keep it up.5 star for giving the code.


27 Jun 2016 Hannah Winnes

26 Jun 2016 Kunal Chaudhury

Kunal Chaudhury (view profile)

Hannah Winnes: In [0,255].

Comment only
26 Jun 2016 Hannah Winnes

Are you requiring images to have value in [0,1] or in [0,255]?

Comment only
14 Jun 2016 Kunal Chaudhury

Kunal Chaudhury (view profile)

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.

Comment only
13 Jun 2016 Hannah Winnes

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);"

16 Apr 2016 Kunal Chaudhury

Kunal Chaudhury (view profile)

Andre Filipe: Yes, one can easily adapt the present code for cross bilateral filtering.

Comment only
15 Apr 2016 Andre Filipe

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

Comment only
11 Mar 2016 Kunal Chaudhury

Kunal Chaudhury (view profile)

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.

Comment only
01 Mar 2016 Mikkel Gammelgaard

Before trying, would this code work for a point cloud of xyz?

Comment only
14 May 2015 Kunal Chaudhury

Kunal Chaudhury (view profile)

Prabhakaran Sengodan: Please see my comments from Nov 19/20.

Comment only
08 May 2015 Prabhakaran Sengodan

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 :)

Comment only
29 Apr 2013 Kunal Chaudhury

Kunal Chaudhury (view profile)

Ben: Yes, you can modify the code for volume data as well. The dimension of the data is immaterial.

Comment only
20 Apr 2013 Ben

Ben (view profile)

A quick question before trying it: does the code support 3D image?

Comment only
20 Nov 2012 Kunal Chaudhury

Kunal Chaudhury (view profile)

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.

Comment only
19 Nov 2012 PeeVee

PeeVee (view profile)

Does setting T to max (255 in my case) decrease the accuracy of the final result?

Comment only
19 Nov 2012 Kunal Chaudhury

Kunal Chaudhury (view profile)

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).

Comment only
17 Nov 2012 PeeVee

PeeVee (view profile)

Most of the time is spent on maxfilter for large image sizes. Is it really necessary, or can we just set T=255?

21 May 2012 Kunal Chaudhury

Kunal Chaudhury (view profile)

Thanks Derek. Bug fixed.

Comment only
18 May 2012 Derek

Derek (view profile)

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

Comment only
14 May 2012 Curtis

Curtis (view profile)

Nice effort!

Comment only
11 May 2012 1.7

screenshot added.

21 May 2012 1.8

Code for joint filtering of multiband images added (Courtsey of Derek).

08 Aug 2012 1.10

A minor update.

22 Aug 2012 1.12

Replaced 'parfor' loop with 'for' loop.

18 Apr 2013 1.13

Replaced rand( ) by randn( ) in the file *demo*.

24 Jun 2014 1.14

Small fixes made to speedup the code.

12 Jul 2015 1.14

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.

13 Jul 2015 1.14

some minor fix.

06 Apr 2016 2.1

new version: optimized to work with narrow range kernels.

06 Apr 2016 2.1

minor fix

12 Apr 2016 2.2

a bug in the maxFilter code was fixed (thanks to Pravin Nair).

01 Jul 2016 2.3

GUI added.

01 Jul 2016 2.3

Snapshot of the GUI added.

08 Jul 2016 2.3

minor fix.

Contact us