def image_gradient(image, horv):
"""apply a sobel filter to the image to approximate the gradient
Parameters
----------
image : ndarray(h, v)
image as an ndarray
horv : string
"h" or "v", direction of gradient.
Returns
-------
image_dir : ndarray(h, v)
directional gradient magnitude at each pixel
"""
axis = 1 if horv == 'h' else 0
grad = ndi.sobel(image, axis, mode='constant', cval=np.nan) / 8.0
return np.nan_to_num(grad)
评论列表
文章目录