Sobel Operator

Sobel detects edges by computing image gradients in X and Y directions.

import cv2
import numpy as np


def sobel_operator(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
grad_x = cv2.Sobel(gray, cv2.CV_64F, 1, 0)
grad_y = cv2.Sobel(gray, cv2.CV_64F, 0, 1)
return cv2.magnitude(grad_x, grad_y)
← Back to Gallery