Skip to content

Commit

Permalink
mean filter on an image
Browse files Browse the repository at this point in the history
  • Loading branch information
susantabiswas committed Nov 12, 2017
1 parent aab547f commit a891379
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
Binary file added Day4/lenna.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Day4/mean_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
''' Apply mean filter on an image '''

import cv2
import numpy as np

img = cv2.imread('lenna.jpg', 0)
new_img = np.copy(img)
prop = img.shape

#we take a 3x3 mask
'''
mask:
0 1 0
1 2 1
0 1 0
'''
for i in range(1, prop[0] - 1):
for j in range(1, prop[1] - 1):
new_img[i][j] = ( img[i-1][j] + img[i][j-1] + img[i][j]*2 + img[i][j+1] + img[i+1][j])/6

cv2.imwrite('mean_filtered.jpg', new_img)
Binary file added Day4/mean_filtered.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day4/original.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a891379

Please sign in to comment.