Skip to content

Instantly share code, notes, and snippets.

@FienSoP
Created January 16, 2019 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save FienSoP/9dcd88192df084f29647d9c37632d4cb to your computer and use it in GitHub Desktop.
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
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