Description
An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image. The filter replaces each cell with the average of surrounding cells. Given a 2D integer matrix img representing a grayscale image, return the image after applying the smoother on each cell.
Examples
img = [[1,1,1],[1,0,1],[1,1,1]][[0,0,0],[0,0,0],[0,0,0]]For the center cell: (1+1+1+1+0+1+1+1+1)/9 = 8/9 = 0 (floor). Corner cells average 4 neighbors: (1+1+1+0)/4 = 0 (floor). All cells round down to 0.
img = [[1]][[1]]A 1x1 image has only one cell with no neighbors, so its smoothed value is itself: 1.
img = [[100,200,100],[50,0,50],[100,200,100]][[87,83,87],[108,100,108],[87,83,87]]For each cell, the average of all valid neighboring cells (including itself) is calculated. The center cell (0) has 8 neighbors plus itself: (100+200+100+50+0+50+100+200+100)/9 = 900/9 = 100. Corner cells have fewer neighbors - top-left averages (100+200+50+0)/4 = 87.
Constraints
- •
m == img.length - •
n == img[i].length - •
1 ≤ m, n ≤ 200