1 of 34

Lab 4

Canny Edge Detectors

Slides Courtesy: Stanford Vision

Ayush Jain

aj3152@nyu.edu

2 of 34

Edge Detection Recap

  • Goal is to identify sudden changes (discontinuities) in an image.

  • Intuitively, most semantic and shape information from the image can be encoded in the edges – More compact than pixels

  • Ideal: artist’s line drawing (but artist is also using object-level knowledge)

3 of 34

Why edges matter?

  • Extract information, recognize objects

  • Recover geometry and viewpoint

4 of 34

How to find edges?

  • surface normal discontinuity

  • depth discontinuity

  • surface color discontinuity

  • illumination discontinuity

5 of 34

Spotting edges by example

6 of 34

Spotting edges by example

7 of 34

Spotting edges by example

8 of 34

Characterizing edges

  • An edge is a place of rapid change in the image intensity function

9 of 34

Characterizing edges

10 of 34

Finite Difference Example

11 of 34

Noise

12 of 34

Smoothing

  • Finite difference filters respond strongly to noise.

  • Image noise results in pixels that look very different from their neighbors.

  • Generally, the larger the noise the stronger the response.

  • What is to be done? – Smoothing the image should help, by forcing pixels different to their neighbors (=noise pixels?) to look more like neighbors

13 of 34

Smoothing with different filters

14 of 34

Solution: Smoothing

15 of 34

Solution: Smoothing

16 of 34

Derivative of Gaussian filter

17 of 34

Designing an optimal edge detector?

  • Good detection: the optimal detector must minimize the probability of false positives (detecting spurious edges caused by noise), as well as that of false negatives (missing real edges)
  • Good localization: the edges detected must be as close as possible to the true edges
  • Single response: the detector must return one point only for each true edge point; that is, minimize the number of local maxima around the true edge

18 of 34

Canny edge detectors

  • Suppress Noise

  • Compute gradient magnitude and direction

  • Apply Non-Maximum Suppression – Assures minimal response

  • Use hysteresis and connectivity analysis to detect edges

19 of 34

Example

20 of 34

Derivative of Gaussian filter

21 of 34

Compute Gradients

22 of 34

Get orientation at each pixel

23 of 34

Get orientation at each pixel

  • Edge occurs where gradient reaches a maxima

  • Suppress non-maxima gradient even if it passes threshold

  • Only eight angle directions possible – Suppress all pixels in each direction which are not maxima – Do this in each marked pixel neighborhood

24 of 34

Remove spurious gradients

25 of 34

Non-maximal suppression

  • Edge occurs where gradient reaches a maxima

  • Suppress non-maxima gradient even if it passes threshold

  • Only eight angle directions possible – Suppress all pixels in each direction which are not maxima – Do this in each marked pixel neighborhood

26 of 34

Non-maximal suppression

27 of 34

Example

28 of 34

Hysteresis Thresholding

  • Define two thresholds: Low and High
    • If less than Low, not an edge
    • If greater than High, strong edge
    • If between Low and High, weak edge

  • For weak edges,
    • Consider its neighbors iteratively
    • Then declare it an “edge pixel” if it is connected to an ‘strong edge pixel’ directly or via pixels between Low and High

29 of 34

Hysteresis Thresholding

30 of 34

Canny Edge Detector

  • Filter image with x, y derivatives of Gaussian

  • Find magnitude and orientation of gradient

  • Non-maximum suppression: – Thin multi-pixel wide “ridges” down to single pixel width

  • Thresholding and linking (hysteresis): – Define two thresholds: low and high – Use the high threshold to start edge curves and the low threshold to continue them

31 of 34

Effect of σ (Gaussian kernel spread/size)

Large-scale edges

Fine edges

32 of 34

Homework 2 &

Canny Edge Detectors

Slides courtesy: Irmak Guzey

33 of 34

Homework 2

  • Follow the Canny edge detector algorithm discussed in previous slides

  • Download the homework2.zip file under Assignments tab in Brightspace

  • Complete only the Canny_Skeleton_Code_Lab.ipynb notebook, zip all files and submit by 10th March 11:59 PM EST.

  • Following tutorial: https://docs.opencv.org/3.4/da/d22/tutorial_py_canny.html might be really useful for the homework 2.

34 of 34

Further Reading