Given the following Python code using OpenCV to apply Canny edge detection, what will be the shape of the output image?
import cv2 import numpy as np image = np.zeros((100, 100), dtype=np.uint8) cv2.rectangle(image, (25, 25), (75, 75), 255, -1) edges = cv2.Canny(image, 50, 150) print(edges.shape)
Remember that Canny edge detection returns an image of the same size as the input.
The Canny function returns an edge map with the same height and width as the input image. So the output shape is (100, 100).
Which pair of threshold values is most likely to detect edges clearly without too much noise in a typical grayscale image?
The high threshold should be significantly higher than the low threshold to filter noise.
Typical good values for Canny thresholds are low around 50 and high around 150, balancing edge detection and noise reduction.
Consider this code snippet:
import cv2
image = cv2.imread('image.jpg')
edges = cv2.Canny(image, 100, 200)
It raises an error. What is the cause?
Canny expects a single channel image.
Canny edge detection requires a grayscale image input. If the image is read in color (3 channels), it causes an error.
Which metric is best suited to quantitatively compare the quality of edges detected by Canny against a ground truth edge map?
Think about how well the detected edges overlap with the true edges.
IoU measures the overlap between predicted edges and ground truth edges, making it suitable for edge detection evaluation.
Why does the Canny edge detection algorithm apply Gaussian smoothing before finding edges?
Think about what noise does to edge detection.
Gaussian smoothing blurs the image slightly to reduce noise, which helps prevent false edge detection in the next steps.