Skip to content

Practice Image Smoother

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#661
LeetCode Problem

Image Smoother

Problem Statement

An image smoother is a filter of the 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 (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 (i.e., the average of the four cells in the red smoother). 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.

Source: Image Smoother on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
img = [[1,1,1],[1,0,1],[1,1,1]]
Output
[[0,0,0],[0,0,0],[0,0,0]]

# Example 2

Input
img = [[100,200,100],[200,50,200],[100,200,100]]
Output
[[137,141,137],[141,138,141],[137,141,137]]

Constraints

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

Related LeetCode Problems

Practice more problems similar to Image Smoother.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.