1 of 37

Lecture 2: Edge detection

CS5670: Computer Vision

2 of 37

Announcements

  • Project 1 (Hybrid Images) is now on the course webpage (see Projects link)
    • Due Friday, Feb 7, by 8pm on Github Classroom
    • Artifact due Monday, Feb 10, by 8pm on CMSX
    • Project to be done individually
    • Skeleton code available soon on Github Classroom – instructions for setting up Python environment on the project webpage
  • Course webpage: https://www.cs.cornell.edu/courses/cs5670/2025sp/
    • Has lectures, projects, office hours, etc
  • In-class Quiz first 10 minutes of class this Thursday

3 of 37

Project 1: Hybrid Images

4 of 37

Project 1 Demo

5 of 37

Reading

  • Szeliski 7.2

6 of 37

Edge detection

TexPoint fonts used in EMF.

Read the TexPoint manual before you delete this box.: AAA

  • Convert a 2D image into a set of curves
    • Extracts salient features of the scene
    • More compact than pixels

7 of 37

Origin of edges

  • Edges are caused by a variety of factors

depth discontinuity

surface color discontinuity

illumination discontinuity

surface normal discontinuity

8 of 37

Images as functions…

  • Edges look like steep cliffs

9 of 37

Characterizing edges

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

image

intensity function�(along horizontal scanline)

first derivative

edges correspond to�extrema of derivative

Source: L. Lazebnik

10 of 37

Image derivatives

  • How can we differentiate a digital image F[x,y]?
    • Option 1: reconstruct a continuous image, f, then compute the derivative
    • Option 2: take discrete derivative (finite difference)

1

-1

How would you implement this as a linear filter?

-1

1

:

:

Source: S. Seitz

11 of 37

Image gradient

  • The gradient of an image:

The gradient points in the direction of most rapid increase in intensity���

The edge strength is given by the gradient magnitude:

The gradient direction is given by:

    • how does this relate to the direction of the edge?�

Source: Steve Seitz

12 of 37

Image gradient

Source: L. Lazebnik

13 of 37

Effects of noise

Where is the edge?

Source: S. Seitz

Noisy input image

14 of 37

Solution: smooth first

f

h

f * h

Source: S. Seitz

To find edges, look for peaks in

15 of 37

Associative property of convolution

  • Differentiation is convolution, and convolution is associative:

  • This saves us one operation:

f

Source: S. Seitz

16 of 37

The 1D Gaussian and its derivatives

17 of 37

2D edge detection filters

Gaussian

derivative of Gaussian (x)

18 of 37

Derivative of Gaussian filter

x-direction

y-direction

19 of 37

The Sobel operator

  • Common approximation of derivative of Gaussian

-1

0

1

-2

0

2

-1

0

1

1

2

1

0

0

0

-1

-2

-1

  • The standard definition of the Sobel operator omits the 1/8 term
      • doesn’t make a difference for edge detection
      • the 1/8 term is needed to get the right gradient magnitude

20 of 37

Sobel operator: example

Source: Wikipedia

21 of 37

22 of 37

Which method is the best way to compute the gradient of an image?

Start presenting to display the poll results on this slide.

23 of 37

Example

original image

Image credit: Joseph Redmon

24 of 37

smoothed gradient magnitude

Finding edges

25 of 37

thresholding

Finding edges

where is the edge?

26 of 37

Get Orientation at Each Pixel

  • Get orientation (below, threshold at minimum gradient magnitude)

θ = atan2(gy, gx)

0

360

Gradient orientation angle

27 of 37

Non-maximum supression

  • Check if pixel is local maximum along gradient direction
    • requires interpolating pixels p and r

28 of 37

Before Non-max Suppression

29 of 37

After Non-max Suppression

30 of 37

Thresholding edges

  • Still some noise
  • Only want strong edges
  • 2 thresholds, 3 cases
    • R > T: strong edge
    • R < T but R > t: weak edge
    • R < t: no edge
  • Why two thresholds?

31 of 37

Connecting edges

  • Strong edges are edges!
  • Weak edges are edges �iff they connect to strong
  • Look in some neighborhood�(usually 8 closest)

32 of 37

Canny edge detector

  1. Filter image with derivative of Gaussian

  • Find magnitude and orientation of gradient

  • Non-maximum suppression

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

Source: D. Lowe, L. Fei-Fei, J. Redmon

MATLAB: edge(image,‘canny’)

33 of 37

Canny edge detector

  • Our first computer vision pipeline!
  • Still a widely used edge detector in computer vision

  • Depends on several parameters:

J. Canny, A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8:679-714, 1986.

: width of the Gaussian blur

high threshold

low threshold

34 of 37

Canny edge detector

Canny with

Canny with

original

  • The choice of depends on desired behavior
    • large detects “large-scale” edges
    • small detects fine edges

Source: S. Seitz

35 of 37

Scale space [Witkin 83]

  • Properties of scale space (w/ Gaussian smoothing)
    • edge position may shift with increasing scale (σ)
    • two edges may merge with increasing scale
    • an edge may not split into two with increasing scale

larger

Gaussian filtered signal

first derivative peaks

36 of 37

Demo

37 of 37

Questions?