A box blur averages every pixel in a window equally, which produces visible blockiness. A Gaussian blur weights the centre most and fades smoothly outward, which is why it looks natural. This problem builds the weights.
For a size × size kernel, with the centre at c = (size - 1) / 2:
Then divide every weight by the total, so they sum to 1.
Task: write gaussian_kernel(size, sigma) returning the normalised kernel as a list of rows, every weight rounded to 4 decimal places.
size is odd, so the centre falls exactly on a pixel. For size = 3, c = 1.0; for size = 5, c = 2.0.(i - c)² + (j - c)² is squared distance from the centre, so the kernel is symmetric in both directions and across both diagonals — a quick visual check.The normalisation is what makes this a blur rather than a brightness change. Weights summing to 1 mean a flat grey region comes out exactly as grey as it went in; weights summing to 1.3 would brighten the whole image by 30%.
And notice what sigma controls: at sigma = 0.5 on a 3×3 kernel, the centre holds about 62% of the weight and the blur is barely perceptible. Raise it and the weight spreads outward until the kernel approaches a flat average. The useful rule is that size should be roughly 6 × sigma — any smaller and you're clipping off weight the formula wanted to give you.