Blurring averages each pixel with its neighbours, which suppresses noise and fine detail. A box blur weights all neighbours equally, which leaves visible blocky artifacts. A Gaussian blur weights neighbours by a bell curve centred on the pixel, so near pixels count more than far ones, and the result looks smooth and natural. The width of the bell is the standard deviation sigma, and the kernel's size should cover about three standard deviations on each side. The kernel must sum to 1 so that blurring preserves overall brightness. Because the 2-D Gaussian is the product of two 1-D Gaussians, it is separable: blurring rows then columns with a 1-D kernel gives the same result as one 2-D convolution at a fraction of the cost.
Implement gaussian_kernel and gaussian_blur.
gaussian_kernel(size, sigma) returns the 1-D kernel of odd length size: w[k] = exp(-(k - r)**2 / (2 sigma**2)) for k = 0..size-1 with r = size // 2, normalized to sum to 1.gaussian_blur(img, size, sigma) blurs a 2-D image by applying the 1-D kernel along rows and then along columns. Pad by size // 2 pixels with edge replication (np.pad(mode='edge')) so the output has the same shape as the input.Along an axis, the blurred value is a weighted sum of size shifted slices of the padded image.
A single bright pixel in a zero image becomes a copy of the 2-D kernel outer(w, w).
No results yet
Run your code to check it against the examples, or submit to run every test.