if choice == "1":
sobel_x = cv2.Sobel(gray_image, cv2.CV_64F, 1, 0, ksize=3)
sobel_y = cv2.Sobel(gray_image, cv2.CV_64F, 0, 1, ksize=3)
combined_sobel = cv2.bitwise_or(sobel_x.astype(np.uint8), sobel_y.astype(np.uint8))
display_image("Sobel Edge Detection", combined_sobel)
elif choice == "2":
# Canny Edge Detection
print("Adjust thresholds for Canny (default: 100 and 200)")
lower_thresh = int(input("Enter Lower threshold: "))
upper_thresh = int(input("Enter Upper threshold: "))
edges = cv2.Canny(gray_image, lower_thresh, upper_thresh)
display_image("Canny Edge Detection", edges)
elif choice == "3":
# Laplacian Edge Detection
laplacian = cv2.Laplacian(gray_image, cv2.CV_64F)
display_image("Laplacian Edge Detection", np.abs(laplacian).astype(np.uint8))
elif choice == "4":
# Gaussian Smoothing
print("Adjust kernel size for Gaussian blur (must be odd, default: 5)")
kernel_size = int(input("Enter kernel size (odd number): "))
blurred = cv2.GaussianBlur(image, (kernel_size, kernel_size), 0)
display_image("Gaussian Smoothed Image", blurred)
elif choice == "5":
print("Adjust kernel size for Median filtering (must be odd, default: 5)")
kernel_size = int(input("Enter kernel size (odd number): "))
median_filtered = cv2.medianBlur(image, kernel_size)
display_image("Median Filtered Image", median_filtered)
elif choice == "6":
print("Exiting...")
break
else:
print("Invalid choice. Please select a number between 1 and 6.")
# Provide the path to an image for the activity
interactive_edge_detection('example.jpg')
To embed this project on your website, copy the following code and paste it into your website's HTML: