def _calc_normal_matrix(self):
x_kernel = np.array([[.25, 0, -.25], [.5, 0, -.5], [.25, 0, -.25]])
y_kernel = np.array([[-.25, -.5, -.25], [0, 0, 0], [.25, .5, .25]])
x_normal = convolve(self.working_mask.astype(float), x_kernel)
y_normal = convolve(self.working_mask.astype(float), y_kernel)
normal = np.dstack((x_normal, y_normal))
height, width = normal.shape[:2]
norm = np.sqrt(y_normal**2 + x_normal**2) \
.reshape(height, width, 1) \
.repeat(2, axis=2)
norm[norm == 0] = 1
unit_normal = normal/norm
return unit_normal
评论列表
文章目录