In [1]:
import cv2
import numpy as np
In [2]:
image = cv2.imread('dragon.jpg',0)

cv2.imshow('Original image',image)
cv2.waitKey()
Out[2]:
-1

We have already explained linear filters for horizontal and vertical edge detection

Reference -->> CNN #002, CNN #003 posts.

In [3]:
# this is how we can create a horizontal edge detector.

# cv2.Sobel(src_gray, depth, x_order, y_order)
# src_gray: The input image.
# depth: The depth of the output image.
# x_order: The order of the derivative in x direction.
# y_order: The order of the derivative in y direction.
# To calculate the gradient in x direction we use: x_order= 1 and y_order= 0.
# To calculate the gradient in x direction we use: x_order= 0 and y_order= 1.
image_X = cv2.Sobel(image, cv2.CV_8UC1, 1, 0)

cv2.imshow("Sobel image", image_X)
cv2.waitKey()
Out[3]:
-1