1D Bilateral Filter
Given a 1D signal, apply bilateral filtering. Unlike Gaussian filtering, the bilateral filter considers both spatial distance and intensity difference.
For each position , compute the filtered value as a weighted average over a window of radius :
where the weight combines spatial and range kernels:
The window ranges from to inclusive.
Round output to 4 decimal places.
Example
signal = [10, 10, 10, 10] sigma_s = 1.0, sigma_r = 1.0, radius = 1
[10.0, 10.0, 10.0, 10.0]
- The given signal is a constant signal with all values being 10, so the intensity difference will always be 0.
- For each position , the weight simplifies to since the intensity difference term becomes .
- The window for each position has a radius of 1, so it includes the current and neighboring positions, but since the signal is constant, the weighted average at each position will be the same as the original value, resulting in no change.
- The final output is therefore the same as the input signal, which is [10.0, 10.0, 10.0, 10.0] after rounding to 4 decimal places.
Constraints
- signal is a list of numeric values
- sigma_s (spatial sigma) > 0
- sigma_r (range sigma) > 0
- radius is a positive integer
- Return list of filtered values rounded to 4 decimal places