To implement the Canny edge detection algorithm on an image
Register Number : 212221243002
Developed by : Sanjay S
import cv2
import matplotlib.pyplot as plt
san = 'san.jpg'
san2 = cv2.imread(san, cv2.IMREAD_GRAYSCALE)
if san2 is None:
print("Error: Could not load image")
exit()
edges = cv2.Canny(san2, threshold1=100, threshold2=200)
plt.figure(figsize=(10, 5))
![alt text](out1.png)
plt.subplot(1, 2, 1)
plt.title('Original Image')
plt.imshow(san2, cmap='gray')
plt.axis('off')
![alt text](ou2.png)
plt.subplot(1, 2, 2)
plt.title('Edges')
plt.imshow(edges, cmap='gray')
plt.axis('off')
![alt text](out3.png)
plt.tight_layout()
plt.show()
![alt text](out4.png)
parameters = [
(50, 150),
(100, 200),
(150, 250)
]
san2 = cv2.imread(san, cv2.IMREAD_GRAYSCALE)
plt.figure(figsize=(15, 5))
![alt text](out5.png)
for i, (threshold1, threshold2) in enumerate(parameters):
edges = cv2.Canny(san2, threshold1, threshold2)
plt.subplot(1, 3, i + 1)
plt.title(f'Thresholds: {threshold1}, {threshold2}')
plt.imshow(edges, cmap='gray')
plt.axis('off')
![alt text](out6.png)
plt.tight_layout()
plt.show()
![alt text](out7.png)