Created
January 16, 2019 09:56
-
-
Save FienSoP/9dcd88192df084f29647d9c37632d4cb to your computer and use it in GitHub Desktop.
Apply Sobel filters on image to get the gradient intensity and edges directions matrices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy import ndimage | |
def sobel_filters(img): | |
Kx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], np.float32) | |
Ky = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]], np.float32) | |
Ix = ndimage.filters.convolve(img, Kx) | |
Iy = ndimage.filters.convolve(img, Ky) | |
G = np.hypot(Ix, Iy) | |
G = G / G.max() * 255 | |
theta = np.arctan2(Iy, Ix) | |
return (G, theta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment