roofline.devPublic Beta

Box Blur

0EASYRankedReport issue

Apply a box blur filter to a grayscale image by averaging pixels in a square neighborhood:

Oij=1Nu=kkv=kkI(i+u)(j+v)O_{ij} = \frac{1}{N} \sum_{u=-k}^{k} \sum_{v=-k}^{k} I_{(i + u)\,(j + v)}

where k=kernel_size/2k = \lfloor \text{kernel\_size}/2 \rfloor and NN is the number of valid pixels in the kernel.

This creates a blurring effect by smoothing out pixel values. The larger the kernel size, the more blurred the result!

Input

  • input_image - grayscale image of shape [width][height] containing floating-point pixel intensities in the range [0,255][0, 255].
  • width - the number of columns in the image.
  • height - the number of rows in the image.
  • kernel_size - the side length of the square blur kernel.

Output

  • output_image - blurred grayscale image of shape [width][height].
Open on a desktop browser to write and submit code.