To perform edge detection using Sobel, Laplacian, and Canny edge detectors.
Anaconda - Python 3.7
Import all the necessary modules for the program.
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 and Using Canny operator from cv2,detect the edges of the image.
DEVELOPED BY: Aadhithya.M
REGISTER NO: 212222100001
import cv2
import matplotlib.pyplot as plt
img=cv2.imread("flight.jpg",0)
gray=cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
gray = cv2.GaussianBlur(gray,(3,3),0)
sobelx = cv2.Sobel(gray,cv2.CV_64F,1,0,ksize=5)
plt.imshow(sobelx,cmap='gray')
plt.title("Sobel X axis")
plt.axis("off")
plt.show()
sobely = cv2.Sobel(gray,cv2.CV_64F,0,1,ksize=5)
plt.imshow(sobely,cmap='gray')
plt.title("Sobel Y axis")
plt.axis("off")
plt.show()
sobelxy = cv2.Sobel(gray,cv2.CV_64F,1,1,ksize=5)
plt.imshow(sobelxy,cmap='gray')
plt.title("Sobel XY axis")
plt.axis("off")
plt.show()
lap=cv2.Laplacian(gray,cv2.CV_64F)
plt.imshow(lap,cmap='gray')
plt.title("Laplacian Edge Detector")
plt.axis("off")
plt.show()
canny=cv2.Canny(gray,120,150)
plt.imshow(canny,cmap='gray')
plt.title("Canny Edge Detector")
plt.axis("off")
plt.show()
![](https://private-user-images.githubusercontent.com/119393540/326152354-0d28f437-9584-49d6-8504-2f258f135969.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUzMTMyMjksIm5iZiI6MTcyNTMxMjkyOSwicGF0aCI6Ii8xMTkzOTM1NDAvMzI2MTUyMzU0LTBkMjhmNDM3LTk1ODQtNDlkNi04NTA0LTJmMjU4ZjEzNTk2OS5wbmc_WC1BbXotQWxnb3JpdGhtPU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5N2I0MTJlNWE0ZWEzOTAzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.oLq1G-dRXbiSL6Zw4FZ1lTx4lHRX0Bc0X2uWEkyhsVU)
![](https://private-user-images.githubusercontent.com/119393540/326152190-8a552ce7-ccf8-429d-b3e4-20418d1c1861.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUzMTMyMjksIm5iZiI6MTcyNTMxMjkyOSwicGF0aCI6Ii8xMTkzOTM1NDAvMzI2MTUyMTkwLThhNTUyY2U3LWNjZjgtNDI5ZC1iM2U0LTIwNDE4ZDFjMTg2MS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTAyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwMlQyMTM1MjlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hN2Q3NTViNGQwMmIyYjU4ODYyZjc1YTllZjM2NGM3MDU0OGYyOWI0YmM5N2I5YzBiNGQ5N2YyZTEyYTg2NGVlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9._1Lri_ks8z1jWf5QdCStiZ_50xitvyGXvpbT8Smmme4)
![](https://private-user-images.githubusercontent.com/119393540/326152198-abe166ea-76df-4e4a-a064-606e5cbdf57d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIj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ZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.7dK1vjAjxSs3-U3O0qEqs9gaRv9kGnm-5X1orw3jDzY)
Thus the edges are detected using Sobel, Laplacian, and Canny edge detectors.