Current pixel image[x + 1, y + 0] + // Mid right image[x - 1, y - 1] + // Low left image[x + 0, y - 1] + // Low center image[x + 1, y - 1]; // Low right newImage[x, y] = Sum / 9; } Return newImage; } The example does not handle the edges of the image, which would not fit inside the kernel, so that these areas remain unblurred. In practice, the issue is better handled by: Introducing an alpha channel to represent the absence of colors; Extending the boundary by filling in values, ranked by quality: Fill in a mirrored image at the border Fill in a constant color extending from the last pixel Pad in a fixed color A number of optimizations can be applied when implementing the box blur of a radius r and N pixels: The box blur is a separable filter, so that only two 1D passes of averaging pixels will be needed, one horizontal and one vertical, for each pixel. This lowers the complexity from to . In digital signal processing terminology, each pass is a moving-average filter. Accumulation. Instead of discarding the sum for each pixel, the algorithm re-uses the previous sum, and updates it by subtracting away the old pixel and adding the new pixel in the blurring range. A summed-area table can be used similarly. This lowers the complexity from to . When being used in multiple passes to approximate a Gaussian blur, the cascaded integrator–comb filter construction allows for doing the equivalent operation in a single pass. See also Gaussian blur Gaussian filter Median filter References Image processing