# What Is the Bilateral Filter Category: LPF, HPF, BPF or BSF?

Im reading about Bilateral filter with images, I knew that it uses Gaussian filter (which is a LPF) as a domain filter plus a range filter and it is used to preserve edges(high freq component).

Can we consider Bilateral filter as a LPF ? .

I searched some articles: 1- Which approach is better for decomposing a image into high frequency and low frequency component?

The answer was that bilateral filter attenuates ""medium frequency "

The answer was to consider bilateral filter as a LPF.

• I posted and an answer. I think the main thing here is to think in the Patch Level. – Royi Oct 5 '19 at 0:25

Neither. To me, filter classes using the notion of frequency bands (low-pass, high-pass, etc.) can be used safely in the linear case. And the bilateral filter is nonlinear. Edges are not really high-frequency: they often have sharp variations across the edge, but slow variation along it. I would consider the bilateral filter as an edge-preserving smoother, a broad and somewhat imprecise class.

Suggested reading: Fast and Provably Accurate Bilateral Filtering, 2016

The bilateral filter is a non-linear filter that uses a range filter along with a spatial filter to perform edge-preserving smoothing of images. A direct computation of the bilateral filter requires O(S) operations per pixel, where S is the size of the support of the spatial filter. In this paper, we present a fast and provably accurate algorithm for approximating the bilateral filter when the range kernel is Gaussian. In particular, for box and Gaussian spatial filters, the proposed algorithm can cut down the complexity to O(1) per pixel for any arbitrary S. The algorithm has a simple implementation involving N+1 spatial filterings, where N is the approximation order. We give a detailed analysis of the filtering accuracy that can be achieved by the proposed approximation in relation to the target bilateral filter. This allows us to estimate the order N required to obtain a given accuracy. We also present comprehensive numerical results to demonstrate that the proposed algorithm is competitive with the state-of-the-art methods in terms of speed and accuracy.

• What about the Patch Level? Have a look on my analysis. – Royi Oct 17 '19 at 11:27

Bilateral Filter is indeed an Edge Preserving Filter.
Moreover, due to being Spatially Variant Non Linear Filter it can be applied using Fourier Transform.
Since it has no representation in Frequency Domain it is not well defined how to classify it into one of the categories: LPF, HPF, BPF or BSF.

Nonetheless, let's try doing some analysis based on analyzing the filter itself and some empirical analysis.
If we look at the filter per patch defined by the radius of the filter, we have fixed weights and we can analyze its effect.

## Analysis of the Bilateral Filter Formula

The Bilateral Filter is given by:

$$O \left( i, j \right) = \frac{1}{ {W}_{i, j} } \sum_{m = -r}^{r} \sum_{n = -r}^{r} w \left( i - m, j - n \right) I \left( i - m, j - n \right)$$

Where:

• $$O \left( i, j \right)$$ - Output image value at pixel $$\left( i, j \right)$$.
• $$I \left( i - m, j - n \right)$$ - Input image value at pixel $$\left( i - m, j - n \right)$$.
• $$r$$ - Radius parameter of the filter.
• $$w \left( i - m, j - n \right)$$ - Weight of the pixel $$\left( i - m, j - n \right)$$ given by $$w \left( i - m, j - n \right) = {w}_{s} \left( i - m, j - n \right) {w}_{r} \left( i - m, j - n \right) = \exp \left( - \frac{ { \left( i - m \right) }^{2} + { \left( j - m \right) }^{2} }{ 2 {\sigma}_{s}^{2} } \right) \exp \left( - \frac{ { \left( I \left( i, j \right) - I \left( m, n \right) \right) }^{2} }{ 2 {\sigma}_{r}^{2} } \right)$$.
• $${W}_{i, j}$$ - Normalization factor of the pixel $$\left( i, j \right)$$ given by $$\sum_{m = -r}^{r} \sum_{n = -r}^{r} w \left( i - m, j - n \right)$$.

So we have the Spatial Weight, which is just classic Gaussian Filter $${w}_{s} \left( i - m, j - n \right)$$ and we have the Range Filter $${w}_{r} \left( i - m, j - n \right)$$.

Assuming we fixed the Spatial Filter with certain Radius and parameter $${\sigma}_{s}$$, let's analyze the effect of the Range Filter.

If we have $${\sigma}_{r} \to \infty$$ then the Range Filter has same value for any pixel and we basically have Spatially Gaussian Filter which is LPF.
For $${\sigma}_{r} \to 0$$ we'll have zero weight for any pixel which is not $$\left( i, j \right)$$, which means Delta Filter (Identity Filter). Namely no effect at all.

So the Bilateral Filter is behaving, per patch, as something between Identity Filter to LPF Filter.

## Empirical Analysis of the Bilateral Filter on Patches

Let's take the Lenna Image and analyze, empirically, the Bilateral Filter over few patches.

The Lenna and selected patches for analysis Image is given by: Let's see how the weights and the Frequency Domain looks:     As can be seen in the results above, the Bilateral Filter is indeed data dependent.
We chose different patches (2 Steps, Texture and Flat) and can see how it behaves for each.

If we look on the Frequency Domain, unless the rangeStd parameter is very low or the patch have high variance it looks like LPF behavior.

## Summary

The Bilateral Filter isn't a classic Linear Spatialy Invariant filter.
Hence it can not be classified like classic filters.
Yet according to the analysis above one could come to this conclusion:

1. When the Bilateral Filter indeed smooths (The rangeStd parameter is modes relative to the data variance) it behaves, at the patch level, like LPF filter.
2. When the rangeStd` is very low compared to the variance of the data in the patch the Bilateral Filter behaves almost as the Delta Filter (Identity).

The main idea here is since this is Spatially Variant filter we have to analyze it on the Patch Level and not the Image Level.

The full code is available on my StackExchange Signal Processing Q60916 GitHub Repository.