import cv2 import numpy as np from scipy import ndimage import matplotlib.pyplot as plt from tqdm import tqdm def _neighbors_conv(image): image = image.astype(np.int32) k = np.array([[255, 255, 255], [255, 0, 255], [255, 255, 255]]) neighborhood_count = ndimage.convolve(image, k, mode='constant', cval=1) neighborhood_count[~image.astype(np.bool_)] = 0 # print(neighborhood_count) return neighborhood_count def spur(image): return _neighbors_conv(image) > 255 def bwmorph(image, fn, n=1): for _ in range(n): image = fn(image) return image t = [[0, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 0, 0]] t = np.array(t) print('neighbor count:') print(_neighbors_conv(t)) print('after spur:') print(bwmorph(t, spur).astype(np.int_))
10-09
6181
05-15
1720
09-28
363
06-12
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交