---
title: "BilateralFilter"
language: "en"
type: "Symbol"
summary: "BilateralFilter[data, \\[Sigma], \\[Mu]] applies a bilateral filter of spatial spread \\[Sigma] and pixel value spread \\[Mu] to data."
keywords: 
- noise removal
- bilateral
- edge-preserving
- edge-preserving smoothing
- edge preserving filter
- data smoothing
- image smoothing
canonical_url: "https://reference.wolfram.com/language/ref/BilateralFilter.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Image Restoration"
    link: "https://reference.wolfram.com/language/guide/ImageRestoration.en.md"
  - 
    title: "Image Processing & Analysis"
    link: "https://reference.wolfram.com/language/guide/ImageProcessing.en.md"
  - 
    title: "Image Filtering & Neighborhood Processing"
    link: "https://reference.wolfram.com/language/guide/ImageFilteringAndNeighborhoodProcessing.en.md"
  - 
    title: "3D Images"
    link: "https://reference.wolfram.com/language/guide/3DImages.en.md"
  - 
    title: "Video Computation: Update History"
    link: "https://reference.wolfram.com/language/guide/VideoComputation-UpdateHistory.en.md"
  - 
    title: "Linear and Nonlinear Filters"
    link: "https://reference.wolfram.com/language/guide/LinearAndNonlinearFilters.en.md"
  - 
    title: "Computational Photography"
    link: "https://reference.wolfram.com/language/guide/ComputationalPhotography.en.md"
related_functions: 
  - 
    title: "GaussianFilter"
    link: "https://reference.wolfram.com/language/ref/GaussianFilter.en.md"
  - 
    title: "MeanShiftFilter"
    link: "https://reference.wolfram.com/language/ref/MeanShiftFilter.en.md"
  - 
    title: "GuidedFilter"
    link: "https://reference.wolfram.com/language/ref/GuidedFilter.en.md"
  - 
    title: "PeronaMalikFilter"
    link: "https://reference.wolfram.com/language/ref/PeronaMalikFilter.en.md"
  - 
    title: "CurvatureFlowFilter"
    link: "https://reference.wolfram.com/language/ref/CurvatureFlowFilter.en.md"
---
# BilateralFilter

BilateralFilter[data, σ, μ] applies a bilateral filter of spatial spread σ and pixel value spread μ to data.

## Details and Options

* ``BilateralFilter`` is a nonlinear local filter used for edge-preserving smoothing. The amount of smoothing is dependent on the values of ``σ`` and ``μ``.

[image]

* ``BilateralFilter`` replaces each pixel by a weighted average of its neighbors, using normalized Gaussian matrices as weights.

* The ``data`` can be any of the following:

|         |                                                   |
| ------- | ------------------------------------------------- |
| list    | arbitrary-rank numerical array                    |
| tseries | temporal data such as TimeSeries, TemporalData, … |
| image   | arbitrary Image or Image3D object                 |
| audio   | an Audio object                                   |
| video   | a Video object                                    |

* When applied to multichannel audio signals and images, the Euclidean distance between channel vectors is computed.

* At the data boundaries, ``BilateralFilter`` uses smaller neighborhoods.

* The following options can be given:

|                   |                  |                              |
| ----------------- | ---------------- | ---------------------------- |
| MaxIterations     | 1                | maximum number of iterations |
| WorkingPrecision  | MachinePrecision | the precision to use         |

* ``BilateralFilter`` uses a Gaussian matrix of spatial radius 5/2 ``σ``.

* ``BilateralFilter`` always returns an image of a real type.

* For large values of ``μ``, bilateral filtering yields results similar to Gaussian filtering.

## Background & Context

``BilateralFilter`` is a filter for smoothing images to remove local variations typically caused by noise, rough textures, etc. ``BilateralFilter`` is often used as a preprocessing step before doing other image analysis operations, such as segmentation. Bilateral filtering can also be used to perform unsharp masking by subtracting the filtered image from the original and then adding the original back in.

``BilateralFilter`` performs a nonlinear edge-preserving smoothing. The smoothing is done by replacing each pixel with a weighted average of its neighbors, where weights are taken from a normalized Gaussian distribution based on color value similarity. Here, the standard deviation ``σ`` and mean ``μ`` of the Gaussian distribution are specified as arguments.

``BilateralFilter`` works with arbitrary grayscale and color images, as well as with 3D and 2D images. When applied to multichannel images, ``BilateralFilter`` does not operate channel-by-channel but rather uses the Euclidean distance between channel vectors.

Other edge-preserving filters include ``MeanShiftFilter`` and ``PeronaMalikFilter``. Similar filters that are not edge preserving include ``MeanFilter`` and ``GaussianFilter``. For large values of the Gaussian distribution mean, bilateral filtering yields results similar to Gaussian filtering.

---

## Examples (24)

### Basic Examples (3)

Bilateral filtering of a vector:

```wl
In[1]:= BilateralFilter[ {1, 0, 1, 4, 4, 5, 2, 1}, 3, 1]

Out[1]= {0.819466, 0.573802, 0.908264, 4.10055, 4.11161, 4.47202, 1.73819, 1.26565}
```

---

Filter a ``TimeSeries`` :

```wl
In[1]:=
ts = TemporalData[TimeSeries, {CompressedData["«1188»"], {{0., 10., 0.1}}, 1, {"Continuous", 1}, {"Continuous", 1}, 1, 
  {ValueDimensions -> 1, ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 
 10.];

In[2]:= filtered = BilateralFilter[ts, 5, 2]

Out[2]=
TemporalData[TimeSeries, {CompressedData["«1186»"], {{0., 10., 0.1}}, 1, {"Continuous", 1}, {"Continuous", 1}, 1, 
  {ValueDimensions -> 1, ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 
 14.3]

In[3]:= ListLinePlot[{ts, filtered}, PlotLegends -> {"original data", "filtered"}]

Out[3]= [image]
```

---

Smooth details in a color image:

```wl
In[1]:= BilateralFilter[[image], 7, .1]

Out[1]= [image]
```

### Scope (8)

#### Data (8)

Bilateral filtering of a list:

```wl
In[1]:=
{ListLinePlot[data = Table[Sign[i - 1] + RandomReal[{-.2, .2}], {i, 0, 2, 0.01}]], 
	ListLinePlot[BilateralFilter[data, 10, .5]]}

Out[1]= {[image], [image]}
```

---

Bilateral filtering of a 2D array:

```wl
In[1]:=
BilateralFilter[(⁠|   |   |   |   |
| - | - | - | - |
| 0 | 3 | 2 | 2 |
| 3 | 9 | 9 | 6 |
| 5 | 8 | 7 | 0 |
| 3 | 1 | 1 | 2 |⁠), 2, 2]//MatrixForm

Out[1]//MatrixForm=
(⁠|         |         |         |         |
| ------- | ------- | ------- | ------- |
| 1.30985 | 2.64764 | 2.09334 | 2.03649 |
| 2.76157 | 8.15788 | 8.12256 | 6.0002  |
| 4.50296 | 7.64208 | 6.98798 | 1.19441 |
| 2.72525 | 1.61384 | 1.50013 | 1.75995 |⁠)
```

---

Filter a ``TimeSeries`` :

```wl
In[1]:=
ts = TemporalData[TimeSeries, {CompressedData["«1188»"], {{0, 1., 0.01}}, 1, {"Continuous", 1}, {"Continuous", 1}, 1, 
  {ValueDimensions -> 1, ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 
 10.1];

In[2]:= filtered = BilateralFilter[ts, 3, 1]

Out[2]=
TemporalData[TimeSeries, {CompressedData["«1186»"], {{0, 1., 0.01}}, 1, {"Continuous", 1}, {"Continuous", 1}, 1, 
  {ValueDimensions -> 1, ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 
 14.3]

In[3]:= ListLinePlot[{ts, filtered}, PlotLegends -> {"original data", "filtered"}]

Out[3]= [image]
```

---

Filter an ``Audio`` signal:

```wl
In[1]:= a = Import["ExampleData/rule30.wav"];

In[2]:= b = BilateralFilter[a, 25, 0.5]

Out[2]= [image]

In[3]:= AudioPlot[{a, b}]

Out[3]= [image]
```

---

Bilateral filtering smooths an image while preserving edges:

```wl
In[1]:= BilateralFilter[[image], 2, 0.2]

Out[1]= [image]
```

---

Filter video frames:

```wl
In[1]:= BilateralFilter[Video["ExampleData/fish.mp4"], 3, .5]

Out[1]= \!\(\*VideoBox["![Embedded Video Player](video://content-m5xdx)"]\)
```

---

Denoise a 3D image:

```wl
In[1]:= BilateralFilter[[image], 5, 0.1]

Out[1]= [image]
```

---

Symbolic computation of a bilateral filter:

```wl
In[1]:= BilateralFilter[{a, b, c}, 1, .1]

Out[1]= {(a + b E^-(1/2) - 50. Abs[-a + b]^2 + c E^-2 - 50. Abs[-a + c]^2/1 + E^-(1/2) - 50. Abs[-a + b]^2 + E^-2 - 50. Abs[-a + c]^2), (b + a E^-(1/2) - 50. Abs[a - b]^2 + c E^-(1/2) - 50. Abs[-b + c]^2/1 + E^-(1/2) - 50. Abs[a - b]^2 + E^-(1/2) - 50. Abs[-b + c]^2), (c + a E^-2 - 50. Abs[a - c]^2 + b E^-(1/2) - 50. Abs[b - c]^2/1 + E^-2 - 50. Abs[a - c]^2 + E^-(1/2) - 50. Abs[b - c]^2)}
```

### Options (6)

#### MaxIterations (2)

By default, one iteration of bilateral filtering is performed:

```wl
In[1]:=
i = [image];
BilateralFilter[i, 2, .05, MaxIterations -> 1]

Out[1]= [image]
```

Run more iterations:

```wl
In[2]:= BilateralFilter[i, 2, .05, MaxIterations -> 10]

Out[2]= [image]
```

---

Repeatedly filter a ``TimeSeries`` :

```wl
In[1]:=
ts = TemporalData[TimeSeries, {CompressedData["«1188»"], {{0, 1., 0.01}}, 1, {"Continuous", 1}, {"Continuous", 1}, 1, 
  {ValueDimensions -> 1, ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 
 10.1];

In[2]:= filtered = BilateralFilter[ts, 3, .3, MaxIterations -> 100]

Out[2]=
TemporalData[TimeSeries, {CompressedData["«1138»"], {{0, 1., 0.01}}, 1, 
  {"Continuous", 1}, {"Continuous", 1}, 1, {ValueDimensions -> 1, 
   ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 14.3]

In[3]:= ListLinePlot[{ts, filtered}, PlotLegends -> {"original data", "filtered"}]

Out[3]= [image]
```

#### WorkingPrecision (4)

By default, ``MachinePrecision`` is used with integer arrays:

```wl
In[1]:= BilateralFilter[{3, 4, 4, 3, 2}, 2, 1]

Out[1]= {3.35545, 3.64977, 3.62782, 3.13314, 2.49868}
```

Perform exact computation instead:

```wl
In[2]:= BilateralFilter[{3, 4, 4, 3, 2}, 2, 1, WorkingPrecision -> ∞]

Out[2]= {(3 + (2/E^5 / 2) + (3/E^9 / 8) + (4/E) + (4/E^5 / 8)/1 + (1/E^5 / 2) + (1/E^9 / 8) + (1/E) + (1/E^5 / 8)), (4 + (2/E^25 / 8) + (3/E) + (3/E^5 / 8) + (4/E^1 / 8)/1 + (1/E^25 / 8) + (1/E) + (1/E^5 / 8) + (1/E^1 / 8)), (4 + (2/E^5 / 2) + (3/E) + (3/E^5 / 8) + (4/E^1 / 8)/1 + (1/E^5 / 2) + (1/E) + (1/E^5 / 8) + (1/E^1 / 8)), (3 + (3/E^9 / 8) + (4/E) + (6/E^5 / 8)/1 + (1/E^9 / 8) + (1/E) + (2/E^5 / 8)), (2 + (4/E^25 / 8) + (7/E^5 / 2) + (3/E^5 / 8)/1 + (1/E^25 / 8) + (2/E^5 / 2) + (1/E^5 / 8))}
```

---

By default, the precision of the input is used for real arrays:

```wl
In[1]:= BilateralFilter[{1.0000000000000000000, 2.0000000000000000000, 3.0000000000000000000, 4.0000000000000000000}, 2, 1]

Out[1]= {1.438168854639410389, 2.076265631390311427, 2.923734368609688573, 3.561831145360589611}
```

Specify the precision to use:

```wl
In[2]:= BilateralFilter[{1.0000000000000000000, 2.0000000000000000000, 3.0000000000000000000, 4.0000000000000000000}, 2, 1, WorkingPrecision -> MachinePrecision]

Out[2]= {1.43817, 2.07627, 2.92373, 3.56183}
```

---

With symbolic arrays, exact computation is used:

```wl
In[1]:= BilateralFilter[{a, b, c}, 1, 1]

Out[1]= {(a + b E^-(1/2) - (1/2) Abs[-a + b]^2 + c E^-2 - (1/2) Abs[-a + c]^2/1 + E^-(1/2) - (1/2) Abs[-a + b]^2 + E^-2 - (1/2) Abs[-a + c]^2), (b + a E^-(1/2) - (1/2) Abs[a - b]^2 + c E^-(1/2) - (1/2) Abs[-b + c]^2/1 + E^-(1/2) - (1/2) Abs[a - b]^2 + E^-(1/2) - (1/2) Abs[-b + c]^2), (c + a E^-2 - (1/2) Abs[a - c]^2 + b E^-(1/2) - (1/2) Abs[b - c]^2/1 + E^-2 - (1/2) Abs[a - c]^2 + E^-(1/2) - (1/2) Abs[b - c]^2)}
```

---

``WorkingPrecision`` is ignored when filtering images:

```wl
In[1]:= BilateralFilter[[image], 2, .5, WorkingPrecision -> Infinity]

Out[1]= [image]
```

An image of a real type is always returned:

```wl
In[2]:= ImageType[%]

Out[2]= "Real"
```

### Applications (5)

Removing noise:

```wl
In[1]:= BilateralFilter[[image], 2, .2]

Out[1]= [image]
```

---

Create a posterization effect by performing multiple iterations:

```wl
In[1]:= BilateralFilter[[image], 2, .05, MaxIterations -> 10]

Out[1]= [image]
```

---

Bilateral filtering with a large color spread value, used for background removal:

```wl
In[1]:= ImageSubtract[ #, BilateralFilter[#, 4, 0.9]] & [[image]]

Out[1]= [image]
```

---

Bilateral filtering as a preprocessing step for image segmentation:

```wl
In[1]:= ClusteringComponents[BilateralFilter[[image], 4, 0.3], 5]// Colorize

Out[1]= [image]
```

---

Unsharp masking using bilateral filtering:

```wl
In[1]:=
img = [image];
ImageAdd[img, ImageSubtract[img, BilateralFilter[img, 5, .2]]]

Out[1]= [image]
```

### Properties & Relations (2)

Bilateral filtering performs noise reduction while preserving edges:

```wl
In[1]:=
data = Table[Sign[i - 1] + RandomReal[{-.2, .2}], {i, 0, 2, 0.01}];
{ListLinePlot[data], ListLinePlot[BilateralFilter[data, 20, .5]]}

Out[1]= {[image], [image]}
```

``MeanFilter`` also reduces noise, but does not preserve edges:

```wl
In[2]:= MeanFilter[data, 20]//ListLinePlot

Out[2]= [image]
```

---

For large values of the Gaussian distribution mean, bilateral filtering yields results similar to Gaussian filtering:

```wl
In[1]:= {BilateralFilter[[image], 2, 2], GaussianFilter[[image], 5]}

Out[1]= [image]
```

## See Also

* [`GaussianFilter`](https://reference.wolfram.com/language/ref/GaussianFilter.en.md)
* [`MeanShiftFilter`](https://reference.wolfram.com/language/ref/MeanShiftFilter.en.md)
* [`GuidedFilter`](https://reference.wolfram.com/language/ref/GuidedFilter.en.md)
* [`PeronaMalikFilter`](https://reference.wolfram.com/language/ref/PeronaMalikFilter.en.md)
* [`CurvatureFlowFilter`](https://reference.wolfram.com/language/ref/CurvatureFlowFilter.en.md)

## Related Guides

* [Image Restoration](https://reference.wolfram.com/language/guide/ImageRestoration.en.md)
* [Image Processing & Analysis](https://reference.wolfram.com/language/guide/ImageProcessing.en.md)
* [Image Filtering & Neighborhood Processing](https://reference.wolfram.com/language/guide/ImageFilteringAndNeighborhoodProcessing.en.md)
* [3D Images](https://reference.wolfram.com/language/guide/3DImages.en.md)
* [Video Computation: Update History](https://reference.wolfram.com/language/guide/VideoComputation-UpdateHistory.en.md)
* [Linear and Nonlinear Filters](https://reference.wolfram.com/language/guide/LinearAndNonlinearFilters.en.md)
* [Computational Photography](https://reference.wolfram.com/language/guide/ComputationalPhotography.en.md)

## History

* [Introduced in 2010 (8.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn80.en.md) \| [Updated in 2012 (9.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn90.en.md) ▪ [2015 (10.2)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn102.en.md) ▪ [2016 (11.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn110.en.md) ▪ [2025 (14.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn143.en.md)