File Exchange

image thumbnail

Fast Bilateral Filter

version 2.3 (65.1 KB) by

Fast bilateral filtering using Fourier approximation.

3.66667
5 Ratings

46 Downloads

Updated

View License

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.

Comments and Ratings (22)

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

Hannah Winnes

Kunal Chaudhury

Kunal Chaudhury (view profile)

Hannah Winnes: In [0,255].

Hannah Winnes

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

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.

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

Kunal Chaudhury

Kunal Chaudhury (view profile)

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

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

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.

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

Kunal Chaudhury

Kunal Chaudhury (view profile)

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

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.

Ben

Ben (view profile)

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

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.

PeeVee

PeeVee (view profile)

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

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

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?

Kunal Chaudhury

Kunal Chaudhury (view profile)

Thanks Derek. Bug fixed.

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

Curtis

Curtis (view profile)

Nice effort!

Updates

2.3

minor fix.

2.3

Snapshot of the GUI added.

2.3

GUI added.

2.2

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

2.1

minor fix

2.1

new version: optimized to work with narrow range kernels.

1.14

some minor fix.

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.

1.14

Small fixes made to speedup the code.

1.13

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

1.12

Replaced 'parfor' loop with 'for' loop.

1.10

A minor update.

1.8

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

1.7

screenshot added.

MATLAB Release
MATLAB 8.4 (R2014b)

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

» Watch video