FastPrepBuild a Gaussian Blur Kernel

Build a Gaussian Blur Kernel

Luma AI logoLuma AI● MediumFULLTIMEOA
Learn

Problem statement

Return a centered k × k Gaussian blur kernel with standard deviation sigma.

For offsets x,y from the center, use a value proportional to exp(-(x²+y²)/(2·sigma²)), then normalize all entries so their sum is 1.

Function

gaussianKernel(k: int, sigma: double) → double[][]

Examples

Example 1

k = 3sigma = 1.0return = [[0.07511360795411151,0.12384140315297397,0.07511360795411151],[0.12384140315297397,0.2041799555716581,0.12384140315297397],[0.07511360795411151,0.12384140315297397,0.07511360795411151]]

The center has the greatest weight and the normalized matrix sums to one.

Constraints

  • 1 <= k <= 31 and k is odd.
  • 0.1 <= sigma <= 20.
  • Results use absolute tolerance 1e-9.

More Luma AI problems

See Luma AI hiring insights
public double[][] gaussianKernel(int k, double sigma) {
    // Build and normalize the k by k kernel.
}
k3
sigma1.0
expected[[0.07511360795411151,0.12384140315297397,0.07511360795411151],[0.12384140315297397,0.2041799555716581,0.12384140315297397],[0.07511360795411151,0.12384140315297397,0.07511360795411151]]
Checking account…