661 Image Smoother
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 surrounding cells and itself. If a cell has less than 8 surrounding cells, then use as many as you can.
Example 1:
Note:
The value in the given matrix is in the range of [0, 255].
The length and width of the given matrix are in the range of [1, 150].
The Idea: Evolve a 3x3 filter along every element in the matrix. Sum the elements as you go, and count the number of active cells to avoid boundary issues.
Complexity: O(n*m) time and O(1) space
Last updated