Изображение (2D-массив numpy с формой (100,200)) содержит только пиксели 2 цвета — черный (0) и белый (255).
Вот мой код на Python:
Код: Выделить всё
img = cv2.imread(filename) # 2 dims, pixel type: np.uint8 (and only 2 possible values: 0 or 255)
rows,cols = img.shape # always (100,200)
for i in range(1,rows-1):
for j in range(1,cols-1):
if ((img[i,j-1] == 255 and img[i,j+1] == 255) or (img[i-1,j] == 255 and img[i+1,j] == 255)):
img[i,j] = 255
Подробнее здесь: https://stackoverflow.com/questions/793 ... -neighbour
Мобильная версия