FastPrepSquare-Neighborhood Image Blur

Square-Neighborhood Image Blur

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

For each grayscale pixel, consider all other in-bounds cells within row and column distance radius. Floor the neighbor mean, then floor the average of that mean and the original pixel. Preserve a pixel with no neighbors.

Return a new matrix using only original-image values for every calculation.

Function

blurImage(image: int[][], radius: int) → int[][]

Examples

Example 1

image = [[9,6],[3,0]]radius = 1return = [[6,5],[4,3]]

Each pixel sees the other three cells.

Example 2

image = [[7]]radius = 0return = [[7]]

The only pixel has no neighbor.

Constraints

  • 1 <= rows,columns <= 500
  • 0 <= pixel <= 255
  • 0 <= radius <= 500

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[][] blurImage(int[][] image, int radius) {
    // Write your code here.
}
image[[9,6],[3,0]]
radius1
expected[[6,5],[4,3]]
Checking account…