def grad_magnitude(img):
"""Calculate the gradient magnitude of an image.
Args:
img The image
Returns:
gradient image"""
img = img / 255.0
sobel_y = np.array([
[-1, -2, -1],
[0, 0, 0],
[1, 2, 1]
])
sobel_x = np.rot90(sobel_y) # rotates counter-clockwise
# apply x/y sobel filter to get x/y gradients
imgx = signal.correlate(img, sobel_x, mode="same")
imgy = signal.correlate(img, sobel_y, mode="same")
imgmag = np.sqrt(imgx**2 + imgy**2)
return imgmag
评论列表
文章目录