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_))
GitHub 加速计划 / opencv31 / opencv
77.38 K
55.71 K
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:2 个月前 )
c3747a68 Added Universal Windows Package build to CI. 6 天前
9b635da5 - 6 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐