Image Smoother

An **image smoother** is a `3 x 3` filter that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue smoother). If one or more of the surrounding cells of a cell is not present, we do not consider it in the average. Given an `m x n` integer matrix `img` representing the grayscale of an image, return the image after applying the smoother on each cell of it.

30:00

Image Smoother
easy
Free written solution
Topics
Companies

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

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

Example 1:
Input: {"img":[[1,1,1],[1,0,1],[1,1,1]]}
Output: [[0,0,0],[0,0,0],[0,0,0]]
Constraints:
  • m=img.lengthm = img.length

  • n=img[i].lengthn = img[i].length

  • 1≤m,n≤2001 \leq m, n \leq 200

  • 0≤img[i][j]≤2550 \leq img[i][j] \leq 255

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"img":[[1,1,1],[1,0,1],[1,1,1]]}

Make an empty 3 x 3 result. Each output cell is the floor of the average of the input cells in its 3 x 3 window, using only the cells that exist.

img (input)

1
1
1
1
0
1
1
1
1

res (smoothed)

slide the 3 x 3 window over every cell

Variables
VariableValue
m3
n3
DepthFunction Call
Stack empty
0/19