Skip to content

Commit 9ca32e7

Browse files
authored
Update image-smoother.py
1 parent b776b51 commit 9ca32e7

1 file changed

Lines changed: 1 addition & 26 deletions

File tree

Python/image-smoother.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,7 @@
2222
# Note:
2323
# The value in the given matrix is in the range of [0, 255].
2424
# The length and width of the given matrix are in the range of [1, 150].
25-
26-
class Solution(object):
27-
def imageSmoother(self, M):
28-
"""
29-
:type M: List[List[int]]
30-
:rtype: List[List[int]]
31-
"""
32-
def getGray(M, i, j):
33-
directions = [[-1, -1], [0, -1], [1, -1], \
34-
[-1, 0], [0, 0], [1, 0], \
35-
[-1, 1], [0, 1], [1, 1]]
36-
37-
total, count = 0, 0.0
38-
for direction in directions:
39-
ii, jj = i + direction[0], j + direction[1]
40-
if 0 <= ii < len(M) and 0 <= jj < len(M[0]):
41-
total += M[ii][jj]
42-
count += 1.0
43-
return int(total / count)
44-
45-
result = [[0 for _ in xrange(len(M[0]))] for _ in xrange(len(M))]
46-
for i in xrange(len(M)):
47-
for j in xrange(len(M[0])):
48-
result[i][j] = getGray(M, i, j);
49-
return result
50-
# Another solution with getGray function simplified.
25+
5126
class Solution(object):
5227
def imageSmoother(self, M):
5328
"""

0 commit comments

Comments
 (0)