Image Smoother

An image smoother is a filter of size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells. If one or more of the surrounding cells of a cell is not present, do not consider it in the average.

Given an m x n integer matrix img representing the grayscale values of an image, return the image after applying the smoother to each cell.

Example 1
1 1 1
1 0 1
1 1 1
Inputimg = [[1,1,1],[1,0,1],[1,1,1]]
Output[[0,0,0],[0,0,0],[0,0,0]]
Each smoothed value rounds down to 0 because every valid neighborhood average is less than 1.
Example 2
100 200 100
200  50 200
100 200 100
Inputimg = [[100,200,100],[200,50,200],[100,200,100]]
Output[[137,141,137],[141,138,141],[137,141,137]]
Corner cells average to 137, edge cells average to 141, and the center cell averages to 138 after rounding down.

Constraints

  • m == img.length
  • n == img[i].length
  • 1 <= m, n <= 200
  • 0 <= img[i][j] <= 255

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate