PIXELBANKv9.1.0
Menu

Given a 1D signal, apply bilateral filtering. Unlike Gaussian filtering, the bilateral filter considers both spatial distance and intensity difference.

For each position ii, compute the filtered value as a weighted average over a window of radius rr:

output[i]=∑jw(i,j)⋅I[j]∑jw(i,j)\text{output}[i] = \frac{\sum_{j} w(i,j) \cdot I[j]}{\sum_{j} w(i,j)}

where the weight combines spatial and range kernels:

w(i,j)=exp⁡(−(i−j)22σs2)⋅exp⁡(−(I[i]−I[j])22σr2)w(i,j) = \exp\left(-\frac{(i-j)^2}{2\sigma_s^2}\right) \cdot \exp\left(-\frac{(I[i]-I[j])^2}{2\sigma_r^2}\right)

The window ranges from max⁡(0,i−r)\max(0, i-r) to min⁡(n−1,i+r)\min(n-1, i+r) inclusive.

Round output to 4 decimal places.

Example:

Input:
signal = [10, 10, 10, 10]
sigma_s = 1.0, sigma_r = 1.0, radius = 1
Output:
[10.0, 10.0, 10.0, 10.0]
Reasoning:
  • The given signal is a constant signal with all values being 10, so the intensity difference (I[i]−I[j])(I[i]-I[j]) will always be 0.
  • For each position ii, the weight w(i,j)w(i,j) simplifies to exp⁡(−(i−j)22σs2)\exp\left(-\frac{(i-j)^2}{2\sigma_s^2}\right) since the intensity difference term becomes exp⁡(0)=1\exp(0) = 1.
  • The window for each position ii 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
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.