To perform edge detection using Sobel, Laplacian, and Canny edge detectors.
Anaconda - Python 3.7
Import the necessary modules.
Load a image using imread() from cv2 module.
Convert the image to grayscale.
Using Sobel operator from cv2,detect the edges of the image.
Using Laplacian operator from cv2,detect the edges of the image.
Using Canny operator from cv2,detect the edges of the image.
Developed By : KAYALVIZHI M
Register Number :212220230024
# Import the packages
import cv2
import matplotlib.pyplot as plt
# Load the image, Convert to grayscale and remove noise
image=cv2.imread("pikachu.jpg")
image1=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow("IMAGE",image1)
cv2.waitKey(0)
cv2.destroyAllWindows()
img=cv2.GaussianBlur(image1,(3,3),0)
plt.figure(1)
plt.imshow(img,cmap='gray')
plt.title('Original')
plt.xticks([])
plt.yticks([])
# SOBEL EDGE DETECTOR
sobelx=cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)
sobely=cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5)
sobelxy=cv2.Sobel(img,cv2.CV_64F,1,1,ksize=5)
plt.figure(1)
plt.imshow(sobelx,cmap='gray')
plt.title('Sobel x')
plt.xticks([])
plt.yticks([])
plt.imshow(sobely,cmap='gray')
plt.title('Sobel y')
plt.xticks([])
plt.yticks([])
plt.imshow(sobelxy,cmap='gray')
plt.title('Sobel xy')
plt.xticks([])
plt.yticks([])
# LAPLACIAN EDGE DETECTOR
laplacian=cv2.Laplacian(img,cv2.CV_64F)
plt.imshow(laplacian,cmap='gray')
plt.title('Laplacian')
plt.xticks([])
plt.yticks([])
# CANNY EDGE DETECTOR
canny_edges=cv2.Canny(img,120,150)
plt.imshow(canny_edges,cmap='gray')
plt.title('Canny Edges')
plt.xticks([])
plt.yticks([])
Thus the edges are detected using Sobel, Laplacian, and Canny edge detectors.