You are viewing a single comment's thread. Return to all comments →
Seems like cookies are disabled on this browser, please enable them to open this website
Morphological Operations: Erosion with a Structuring Element
You are viewing a single comment's thread. Return to all comments →
import numpy as np
image = np.array([
[0, 0, 1, 1, 0],
[0, 0, 1, 1, 0],
[0, 0, 1, 1, 0],
[1, 1, 1, 1, 1]
])
row = image.shape[0]
column = image.shape[1]
arr = np.copy(image)
for i in range(row):
for j in range(column):
if i in [1,2]:
# Check up and down
if image[i-1,j] == 0 or image[i+1, j] == 0:
arr[i,j] = 0
else:
arr[i,j] = 0
for i in range(arr.shape[0]):
line = ''
for j in range(arr.shape[1]):
line += str(arr[i][j])
print(line)