Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Image Smoother.py #2301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Image Smoother.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution:
def imageSmoother(self, img: List[List[int]]) -> List[List[int]]:
if not img: return []

rows, cols = len(img), len(img[0])
smoothed_img = [[0 for _ in range(cols)] for _ in range(rows)]

for i in range(rows):
for j in range(cols):
total, count = 0, 0

# Iterating through the neighboring cells including the cell itself
for x in range(max(0, i-1), min(i+2, rows)):
for y in range(max(0, j-1), min(j+2, cols)):
total += img[x][y]
count += 1

# Assign the floor value of the average to the smoothed_img
smoothed_img[i][j] = total // count

return smoothed_img