Gaussian Blur Kernel
Gaussian Blur Kernel
Gaussian blur is the most widely used smoothing filter in image processing and computer vision. The filter is defined by a 2D kernel whose weights follow a Gaussian distribution, giving more influence to nearby pixels and less to distant ones.
Given an odd kernel size and a standard deviation sigma, generate the normalized 2D Gaussian kernel.
Algorithm
- Find the center of the kernel: center = size // 2.
- For each position (i, j), compute offsets x = j - center and y = i - center.
- Compute the unnormalized weight using the Gaussian function:
- Divide every entry by the sum of all entries so the kernel sums to 1.
Examples
Input:
size = 3, sigma = 1.0
Output (rounded to 4 decimals):
[[0.0751, 0.1238, 0.0751], [0.1238, 0.2042, 0.1238], [0.0751, 0.1238, 0.0751]]
The center has the largest weight. The kernel is symmetric and sums to 1.0.
Input:
size = 1, sigma = 1.0
Output:
[[1.0]]
A single-element kernel always normalizes to 1.0 regardless of sigma.
Hint 1
The center of a kernel of size n is at index n // 2. Offsets x and y measure distance from this center.
Hint 2
After computing all raw Gaussian values, divide each by the total sum. This ensures the kernel sums to 1.0 without needing the full Gaussian normalization constant.
Requirements
- Compute Gaussian weights using the formula with correct offsets from center
- Normalize the kernel so all entries sum to exactly 1.0
- Return a 2D list of floats with dimensions size x size
Constraints
- size is an odd positive integer (1, 3, 5, ...)
- sigma is a positive float
- Return a 2D list of floats that sums to 1.0
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: number
Accepts: number
Gaussian Blur Kernel
Gaussian Blur Kernel
Gaussian blur is the most widely used smoothing filter in image processing and computer vision. The filter is defined by a 2D kernel whose weights follow a Gaussian distribution, giving more influence to nearby pixels and less to distant ones.
Given an odd kernel size and a standard deviation sigma, generate the normalized 2D Gaussian kernel.
Algorithm
- Find the center of the kernel: center = size // 2.
- For each position (i, j), compute offsets x = j - center and y = i - center.
- Compute the unnormalized weight using the Gaussian function:
- Divide every entry by the sum of all entries so the kernel sums to 1.
Examples
Input:
size = 3, sigma = 1.0
Output (rounded to 4 decimals):
[[0.0751, 0.1238, 0.0751], [0.1238, 0.2042, 0.1238], [0.0751, 0.1238, 0.0751]]
The center has the largest weight. The kernel is symmetric and sums to 1.0.
Input:
size = 1, sigma = 1.0
Output:
[[1.0]]
A single-element kernel always normalizes to 1.0 regardless of sigma.
Hint 1
The center of a kernel of size n is at index n // 2. Offsets x and y measure distance from this center.
Hint 2
After computing all raw Gaussian values, divide each by the total sum. This ensures the kernel sums to 1.0 without needing the full Gaussian normalization constant.
Requirements
- Compute Gaussian weights using the formula with correct offsets from center
- Normalize the kernel so all entries sum to exactly 1.0
- Return a 2D list of floats with dimensions size x size
Constraints
- size is an odd positive integer (1, 3, 5, ...)
- sigma is a positive float
- Return a 2D list of floats that sums to 1.0
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: number
Accepts: number