PIXELBANKv9.1.0
Menu

Compute the Gaussian scale space of a 1D signal by convolving it with Gaussian kernels at multiple scales.

Given a 1D signal and a list of sigma (σ\sigma) values, compute the scale-space representation by convolving the signal with a 1D Gaussian kernel at each scale.

The 1D Gaussian kernel:

G(x,σ)=12πσe−x22σ2G(x, \sigma) = \frac{1}{\sqrt{2\pi}\sigma} e^{-\frac{x^2}{2\sigma^2}}

Algorithm for each sigma:

  1. Determine kernel radius: r=⌈3σ⌉r = \lceil 3\sigma \rceil (capture 99.7% of the distribution)
  2. Build the kernel: compute G(x,σ)G(x, \sigma) for x∈[−r,r]x \in [-r, r]
  3. Normalize the kernel so it sums to 1
  4. Convolve the signal with the kernel (using zero-padding at boundaries)

Return a list of lists, where each inner list is the smoothed signal at that scale. Round each value to 4 decimal places.

Example:

Input:
signal = [0, 0, 1, 0, 0]
sigmas = [0.5]
Output:
[[0.0003, 0.1065, 0.7866, 0.1065, 0.0003]]
Reasoning:
  • Determine the kernel radius: r=⌈3σ⌉=⌈3â‹…0.5⌉=⌈1.5⌉=2r = \lceil 3\sigma \rceil = \lceil 3 \cdot 0.5 \rceil = \lceil 1.5 \rceil = 2
  • Build and normalize the kernel: compute G(x,0.5)G(x, 0.5) for x∈[−2,2]x \in [-2, 2] and normalize so it sums to 1
  • Convolve the signal [0, 0, 1, 0, 0] with the normalized kernel, using zero-padding at boundaries, resulting in the smoothed signal
  • Round each value in the smoothed signal to 4 decimal places, yielding the output: [[0.0003, 0.1065, 0.7866, 0.1065, 0.0003]]

Constraints:

  • signal: List of floats (1D signal)
  • sigmas: List of floats (sigma values for each scale)
  • Return: List of lists (one smoothed signal per sigma)
  • Kernel radius = ceil(3 * sigma)
  • Use zero-padding for boundary handling
  • Round to 4 decimal places
  • Use math module for exp and sqrt
🔒

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.
Gaussian Scale Space - Medium | PixelBank