Image Smoother

Given an `m x n` integer matrix `img`, for each cell compute the average of it and its 8-direction neighbors (floor of mean). Return the smoothed image. Use neighbor checking and boundary conditions.

Input Format

2D list of ints.

Output Format

2D list of ints.

Constraints

  • m,n ≤ 200; pixel values [0,255].

Examples

Example 1:

Input:

img = [[1,1,1],[1,0,1],[1,1,1]]

Output:

[[0,0,0],[0,0,0],[0,0,0]]

Explanation:

Each center is (1+1+1+1+0+1+1+1+1)/9 = 8/9=0; edges avg = floor of neighbor sum.

Loading...
Image Smoother - Matrix DSA Problem