Bird
Raised Fist0
Computer Visionml~20 mins

Edge detection (Canny) in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Canny Edge Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Canny edge detection with different thresholds

Given the following Python code using OpenCV to apply Canny edge detection, what will be the shape of the output image?

Computer Vision
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)
A(98, 98)
B(50, 50)
C(102, 102)
D(100, 100)
Attempts:
2 left
💡 Hint

Remember that Canny edge detection returns an image of the same size as the input.

Model Choice
intermediate
2:00remaining
Choosing parameters for Canny edge detection

Which pair of threshold values is most likely to detect edges clearly without too much noise in a typical grayscale image?

ALow threshold = 100, High threshold = 110
BLow threshold = 50, High threshold = 150
CLow threshold = 10, High threshold = 200
DLow threshold = 200, High threshold = 250
Attempts:
2 left
💡 Hint

The high threshold should be significantly higher than the low threshold to filter noise.

🔧 Debug
advanced
2:00remaining
Why does this Canny edge detection code raise an error?

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?

AThe image is not converted to grayscale before applying Canny
BThe threshold values are invalid (should be between 0 and 1)
CThe image path is incorrect
DCanny requires a color image, but a grayscale image was given
Attempts:
2 left
💡 Hint

Canny expects a single channel image.

Metrics
advanced
2:00remaining
Evaluating edge detection quality

Which metric is best suited to quantitatively compare the quality of edges detected by Canny against a ground truth edge map?

AMean Squared Error (MSE)
BAccuracy
CIntersection over Union (IoU)
DRoot Mean Squared Error (RMSE)
Attempts:
2 left
💡 Hint

Think about how well the detected edges overlap with the true edges.

🧠 Conceptual
expert
2:00remaining
Understanding the role of Gaussian smoothing in Canny edge detection

Why does the Canny edge detection algorithm apply Gaussian smoothing before finding edges?

ATo reduce noise and avoid detecting false edges
BTo increase the contrast of edges
CTo sharpen the image details
DTo convert the image to grayscale
Attempts:
2 left
💡 Hint

Think about what noise does to edge detection.

Practice

(1/5)
1. What is the main purpose of the Canny edge detection algorithm in computer vision?
easy
A. To resize images without losing quality
B. To colorize black and white images
C. To blur an image for noise reduction
D. To find clear edges in an image by detecting boundaries

Solution

  1. Step 1: Understand the goal of edge detection

    Edge detection aims to find where objects start and end by detecting sharp changes in brightness.
  2. Step 2: Recognize Canny's role

    Canny edge detection specifically finds clear edges by using gradients and thresholds to highlight boundaries.
  3. Final Answer:

    To find clear edges in an image by detecting boundaries -> Option D
  4. Quick Check:

    Edge detection = finding boundaries [OK]
Hint: Edges show object borders clearly in images [OK]
Common Mistakes:
  • Confusing edge detection with image coloring
  • Thinking Canny blurs images
  • Assuming it resizes images
2. Which of the following is the correct way to call the Canny edge detector function in OpenCV (Python)?
easy
A. cv2.Canny(image, threshold1, threshold2)
B. cv2.canny(image, threshold1, threshold2)
C. cv2.Canny(image, threshold2, threshold1)
D. cv2.Canny(image)

Solution

  1. Step 1: Recall OpenCV function naming

    OpenCV functions are case-sensitive; the correct function is Canny with uppercase C.
  2. Step 2: Check required parameters

    The function requires the image and two threshold values in order: low threshold first, then high threshold.
  3. Final Answer:

    cv2.Canny(image, threshold1, threshold2) -> Option A
  4. Quick Check:

    Correct function name and parameter order = A [OK]
Hint: Function names are case-sensitive; check parameter order [OK]
Common Mistakes:
  • Using lowercase 'canny' instead of 'Canny'
  • Swapping threshold1 and threshold2
  • Omitting required threshold parameters
3. Given the following Python code snippet using OpenCV, what will be the shape of the output image after applying Canny edge detection?
import cv2
image = cv2.imread('photo.jpg')
edges = cv2.Canny(image, 100, 200)
print(edges.shape)
medium
A. (height, width)
B. (height, width, 3)
C. (width, height)
D. (height, width, 1)

Solution

  1. Step 1: Understand input image shape

    Original image read by cv2.imread is usually (height, width, 3) for color images.
  2. Step 2: Check output of cv2.Canny

    Canny outputs a single-channel (grayscale) edge map, so shape is (height, width) without color channels.
  3. Final Answer:

    (height, width) -> Option A
  4. Quick Check:

    Canny output is grayscale edges = (height, width) [OK]
Hint: Canny output is single-channel grayscale image [OK]
Common Mistakes:
  • Assuming output keeps 3 color channels
  • Confusing width and height order
  • Expecting a 3D shape for edges
4. You run Canny edge detection with thresholds 50 and 150 but get too many noisy edges. Which fix below correctly reduces noise in the output?
medium
A. Use a color image instead of grayscale
B. Decrease both thresholds to lower values
C. Increase both thresholds to higher values
D. Remove Gaussian blur before Canny

Solution

  1. Step 1: Understand threshold effect on noise

    Lower thresholds detect more edges including noise; higher thresholds reduce noise by ignoring weak edges.
  2. Step 2: Choose correct adjustment

    Increasing thresholds filters out weak noisy edges, improving edge quality.
  3. Final Answer:

    Increase both thresholds to higher values -> Option C
  4. Quick Check:

    Higher thresholds reduce noise in edges [OK]
Hint: Higher thresholds filter out weak noisy edges [OK]
Common Mistakes:
  • Lowering thresholds increases noise
  • Using color images directly confuses Canny
  • Skipping blur preprocessing increases noise
5. You want to detect edges on a noisy grayscale image using Canny. Which sequence of steps will best improve edge detection results?
hard
A. Apply median blur, then Canny with low thresholds, then erode edges
B. Apply Gaussian blur, then Canny with tuned thresholds, then dilate edges
C. Apply Canny directly with default thresholds, then convert to color
D. Resize image larger, then apply Canny with high thresholds, then invert edges

Solution

  1. Step 1: Preprocess noisy image with Gaussian blur

    Gaussian blur smooths noise while preserving edges, improving Canny input.
  2. Step 2: Apply Canny with tuned thresholds

    Adjust thresholds to balance edge detection and noise filtering.
  3. Step 3: Use dilation to strengthen edges

    Dilation thickens edges, making them clearer for further processing.
  4. Final Answer:

    Apply Gaussian blur, then Canny with tuned thresholds, then dilate edges -> Option B
  5. Quick Check:

    Blur + tuned thresholds + dilation = best edge detection [OK]
Hint: Blur first, tune thresholds, then enhance edges [OK]
Common Mistakes:
  • Using low thresholds increases noise
  • Skipping blur causes noisy edges
  • Converting to color after Canny is useless