def _mkConvKernel(ksize, orientations):
# create line shaped kernels, like [ | / - \ ] for 4 orientations
assert ksize[0] % 2 and ksize[1] % 2
k0, k1 = ksize
mx, my = (k0 // 2) + 1, (k1 // 2) + 1
kernel = np.empty((orientations, k0, k1))
for i, a in enumerate(_angles(orientations)):
# make line kernel
x = int(round(4 * np.cos(a) * k0))
y = int(round(4 * np.sin(a) * k1))
k = np.zeros((2 * k0, 2 * k1), dtype=np.uint8)
cv2.line(k, (-x + k0, -y + k1), (x + k0, y + k1),
255,
thickness=1, lineType=cv2.LINE_AA)
# resize and scale 0-1:
ki = k[mx:mx + k0, my:my + k1].astype(float) / 255
kernel[i] = ki / ki.sum()
return kernel
评论列表
文章目录