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_))
opencv提取骨架找端点,根据端点去掉毛刺
最新推荐文章于 2024-04-29 17:55:25 发布