SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
Robert Collins
CSE486, Penn State




                              Lecture 5:
                     Gradients and Edge Detection
                       Reading: T&V Section 4.1 and 4.2
Robert Collins
CSE486, Penn State
                        What Are Edges?
           Simple answer: discontinuities in intensity.
Robert Collins
CSE486, Penn State
                     Boundaries of objects
Robert Collins
CSE486, Penn State
                     Boundaries of Material Properties




D.Jacobs, U.Maryland
Robert Collins
CSE486, Penn State
                       Boundaries of Lighting




D.Jacobs, U.Maryland
Robert Collins
CSE486, Penn State
                     Types of Edges (1D Profiles)
   • Edges can be modeled according to their intensity profiles:

   • Step edge:                                                    step
         – the image intensity abruptly
           changes from one value to
           one side of the discontinuity
           to a different value on the
           opposite side.

                                                                   ramp
   • Ramp edge:
         – a step edge where the
           intensity change is not
           instantaneous but occurs
           over a finite distance.
                                           step        ramp

M.Nicolescu, UNR
Robert Collins
CSE486, Penn State
                     Examples
Robert Collins
CSE486, Penn State
                     Types of Edges (1D Profiles)
   • Ridge edge:
         – the image intensity abruptly changes value but then returns
           to the starting value within some short distance
         – generated usually by lines




M.Nicolescu, UNR
Robert Collins
CSE486, Penn State
                     Examples
Robert Collins
CSE486, Penn State
                     Examples
Robert Collins
CSE486, Penn State
                     Types of Edges (1D Profiles)
   • Roof edge:
         – a ridge edge where the intensity change is not instantaneous
           but occurs over a finite distance
         – generated usually by the intersection of surfaces




M.Nicolescu, UNR
Robert Collins
CSE486, Penn State
                     Examples
Robert Collins
CSE486, Penn State
                     Step/Ramp Edge Terminology
   • Edge descriptors
         –    Edge normal: unit vector in the direction of maximum intensity change.
         –    Edge direction: unit vector along edge (perpendicular to edge normal).
         –    Edge position or center: the image position at which the edge is located.
         –    Edge strength or magnitude: local image contrast along the normal.




             Important point: All of this information can be
             computed from the gradient vector field!!
M.Nicolescu, UNR
Robert Collins
CSE486, Penn State
                           Summary of Gradients




                                           T
        Gradient Vector:          =[   ,   ]


                     Magnitude:                Orientation
M.Hebert, CMU
Robert Collins

              Simple Edge Detection Using Gradients
CSE486, Penn State




   A simple edge detector using gradient magnitude

         •Compute gradient vector at each pixel by
         convolving image with horizontal and
         vertical derivative filters

         •Compute gradient magnitude at each pixel

         •If magnitude at a pixel exceeds a threshold,
         report a possible edge point.


M.Nicolescu, UNR
Robert Collins

               Compute Spatial Image Gradients
CSE486, Penn State


                                                   Ix=dI(x,y)/dx
                       I(x+1,y) - I(x-1,y)
                                   2
    I(x,y)
                        Partial derivative wrt x




                       I(x,y+1) - I(x,y-1)
                                   2               Iy=dI(x,y)/dy
                        Partial derivative wrt y




      Replace with your favorite
      smoothing+derivative operator
Robert Collins

              Simple Edge Detection Using Gradients
CSE486, Penn State




   A simple edge detector using gradient magnitude

         •Compute gradient vector at each pixel by
         convolving image with horizontal and
         vertical derivative filters

         •Compute gradient magnitude at each pixel

         •If magnitude at a pixel exceeds a threshold,
         report a possible edge point.


M.Nicolescu, UNR
Robert Collins
CSE486, Penn State
                     Compute Gradient Magnitude
               I(x,y)        Ix       Iy




     Magnitude of gradient
      sqrt(Ix.^2 + Iy.^2)

     Measures steepness of
     slope at each pixel
     (= edge contrast)
Robert Collins

              Simple Edge Detection Using Gradients
CSE486, Penn State




   A simple edge detector using gradient magnitude

         •Compute gradient vector at each pixel by
         convolving image with horizontal and
         vertical derivative filters

         •Compute gradient magnitude at each pixel

         •If magnitude at a pixel exceeds a threshold,
         report a possible edge point.


M.Nicolescu, UNR
Robert Collins
CSE486, Penn State
                     Threshold to Find Edge Pixels

   • Example – cont.:                     Binary edge image


                              Threshold
                              Mag > 30




M.Nicolescu, UNR
Robert Collins

                Edge Detection Using Gradient Magnitude
CSE486, Penn State




M.Nicolescu, UNR
Robert Collins
CSE486, Penn State
                             Issues to Address
                     How should we choose the threshold?




                > 10                > 30             > 80


M.Nicolescu, UNR
Robert Collins

                Trade-off: Smoothing vs Localization
CSE486, Penn State




M.Hebert, CMU
Robert Collins
CSE486, Penn State
                       Issues to Address
                     Edge thinning and linking




       smoothing+thresholding
       gives us a binary mask      we want thin, one-pixel
       with “thick” edges          wide, connected contours

M.Nicolescu, UNR
Robert Collins
CSE486, Penn State
                     Canny Edge Detector
                 An important case study

                 Probably, the most used edge detection
                 algorithm by C.V. practitioners

                 Experiments consistently show that it
                 performs very well


     J. Canny A Computational Approach to Edge Detection,
     IEEE Transactions on Pattern Analysis and Machine
     Intelligence, Vol 8, No. 6, Nov 1986
Robert Collins
CSE486, Penn State
                      Formal Design of an
                     Optimal Edge Detector

        • Edge detection involves 3 steps:
              – Noise smoothing
              – Edge enhancement
              – Edge localization
        • J. Canny formalized these steps to design an
          optimal edge detector




O.Camps, PSU
Robert Collins
CSE486, Penn State
                          Edge Model (1D)

         • An ideal edge can be modeled as an step
                      A
                                                 0 if x < 0
                                       G ( x) = 
                                                 A if x ≤ 0

          • Additive, White Gaussian Noise
               – RMS noise amplitude/unit length no2



O.Camps, PSU
Robert Collins
CSE486, Penn State
                     Performance Criteria (1)


        • Good detection
             – The filter must have a stronger response at the
               edge location (x=0) than to noise




O.Camps, PSU
Robert Collins
CSE486, Penn State
                     Performance Criteria (2)


        • Good Localization
             – The filter response must be maximum very
               close to x=0




                                              X=0



O.Camps, PSU
Robert Collins
CSE486, Penn State
                     Performance Criteria (3)


        • Low False Positives
             – There should be only one maximum in a
               reasonable neighborhood of x=0




                                            large

O.Camps, PSU
Robert Collins
CSE486, Penn State
                     Canny Edge Detector

     • Canny found a linear, continuous filter that
       maximized the three given criteria.
     • There is no closed-form solution for the optimal filter.
     • However, it looks VERY SIMILAR to the derivative
       of a Gaussian.
Robert Collins
CSE486, Penn State   Recall: Practical Issues
                      for Edge Detection
     Thinning and linking    Choosing a magnitude threshold




                                           OR

           Canny has good
           answers to all!
Robert Collins
CSE486, Penn State
                               Thinning          note: do thinning
                                                 before thresholding!

                                                        mag(x0) = maximum




                                magnitude
                                                       x0    location along slice



    We want to mark points along curve where the magnitude is largest.
    We can do this by looking for a maximum along a 1D intensity
      slice normal to the curve (non-maximum supression).
    These points should form a one-pixel wide curve.
Robert Collins
CSE486, Penn State
                     Which Threshold to Pick?




                                 Two thresholds applied to gradient magnitude
    problem:
             •If the threshold is too high:
                   –Very few (none) edges
                       •High MISDETECTIONS, many gaps
             •If the threshold is too low:
                   –Too many (all pixels) edges
                       •High FALSE POSITIVES, many extra edges
Robert Collins

                SOLUTION: Hysteresis Thresholding
CSE486, Penn State



            Allows us to apply both! (e.g. a “fuzzy” threshold)

         •Keep both a high threshold H and a low threshold L.
         •Any edges with strength < L are discarded.
         •Any edge with strength > H are kept.
         •An edge P with strength between L and H is kept
           only if there is a path of edges with strength > L
           connecting P to an edge of strength > H.

         •In practice, this thresholding is combined with
            edge linking to get connected contours
Robert Collins
CSE486, Penn State
                     Example of Hysteresis Thresholding




M.Hebert, CMU
Canny Edges: Examples
Robert Collins
CSE486, Penn State




Forsyth and Ponce
Robert Collins
CSE486, Penn State




                     fine scale
                     high
                     threshold




Forsyth and Ponce
Robert Collins
CSE486, Penn State




                     coarse
                     scale,
                     high
                     threshold




Forsyth and Ponce
Robert Collins
CSE486, Penn State




                     coarse
                     scale
                     low
                     threshold




Forsyth and Ponce
Robert Collins
CSE486, Penn State
                     Complete Canny Algorithm




 See textbook for more details.
M.Hebert, CMU

Weitere ähnliche Inhalte

Mehr von zukun

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009
zukun
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCV
zukun
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Information
zukun
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statistics
zukun
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
zukun
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer vision
zukun
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluation
zukun
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-software
zukun
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptors
zukun
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectors
zukun
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-intro
zukun
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video search
zukun
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video search
zukun
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video search
zukun
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learning
zukun
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer vision
zukun
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick start
zukun
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysis
zukun
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structures
zukun
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities
zukun
 

Mehr von zukun (20)

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCV
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Information
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statistics
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer vision
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluation
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-software
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptors
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectors
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-intro
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video search
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video search
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video search
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learning
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer vision
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick start
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysis
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structures
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities
 

Lecture05

  • 1. Robert Collins CSE486, Penn State Lecture 5: Gradients and Edge Detection Reading: T&V Section 4.1 and 4.2
  • 2. Robert Collins CSE486, Penn State What Are Edges? Simple answer: discontinuities in intensity.
  • 3. Robert Collins CSE486, Penn State Boundaries of objects
  • 4. Robert Collins CSE486, Penn State Boundaries of Material Properties D.Jacobs, U.Maryland
  • 5. Robert Collins CSE486, Penn State Boundaries of Lighting D.Jacobs, U.Maryland
  • 6. Robert Collins CSE486, Penn State Types of Edges (1D Profiles) • Edges can be modeled according to their intensity profiles: • Step edge: step – the image intensity abruptly changes from one value to one side of the discontinuity to a different value on the opposite side. ramp • Ramp edge: – a step edge where the intensity change is not instantaneous but occurs over a finite distance. step ramp M.Nicolescu, UNR
  • 8. Robert Collins CSE486, Penn State Types of Edges (1D Profiles) • Ridge edge: – the image intensity abruptly changes value but then returns to the starting value within some short distance – generated usually by lines M.Nicolescu, UNR
  • 10. Robert Collins CSE486, Penn State Examples
  • 11. Robert Collins CSE486, Penn State Types of Edges (1D Profiles) • Roof edge: – a ridge edge where the intensity change is not instantaneous but occurs over a finite distance – generated usually by the intersection of surfaces M.Nicolescu, UNR
  • 12. Robert Collins CSE486, Penn State Examples
  • 13. Robert Collins CSE486, Penn State Step/Ramp Edge Terminology • Edge descriptors – Edge normal: unit vector in the direction of maximum intensity change. – Edge direction: unit vector along edge (perpendicular to edge normal). – Edge position or center: the image position at which the edge is located. – Edge strength or magnitude: local image contrast along the normal. Important point: All of this information can be computed from the gradient vector field!! M.Nicolescu, UNR
  • 14. Robert Collins CSE486, Penn State Summary of Gradients T Gradient Vector: =[ , ] Magnitude: Orientation M.Hebert, CMU
  • 15. Robert Collins Simple Edge Detection Using Gradients CSE486, Penn State A simple edge detector using gradient magnitude •Compute gradient vector at each pixel by convolving image with horizontal and vertical derivative filters •Compute gradient magnitude at each pixel •If magnitude at a pixel exceeds a threshold, report a possible edge point. M.Nicolescu, UNR
  • 16. Robert Collins Compute Spatial Image Gradients CSE486, Penn State Ix=dI(x,y)/dx I(x+1,y) - I(x-1,y) 2 I(x,y) Partial derivative wrt x I(x,y+1) - I(x,y-1) 2 Iy=dI(x,y)/dy Partial derivative wrt y Replace with your favorite smoothing+derivative operator
  • 17. Robert Collins Simple Edge Detection Using Gradients CSE486, Penn State A simple edge detector using gradient magnitude •Compute gradient vector at each pixel by convolving image with horizontal and vertical derivative filters •Compute gradient magnitude at each pixel •If magnitude at a pixel exceeds a threshold, report a possible edge point. M.Nicolescu, UNR
  • 18. Robert Collins CSE486, Penn State Compute Gradient Magnitude I(x,y) Ix Iy Magnitude of gradient sqrt(Ix.^2 + Iy.^2) Measures steepness of slope at each pixel (= edge contrast)
  • 19. Robert Collins Simple Edge Detection Using Gradients CSE486, Penn State A simple edge detector using gradient magnitude •Compute gradient vector at each pixel by convolving image with horizontal and vertical derivative filters •Compute gradient magnitude at each pixel •If magnitude at a pixel exceeds a threshold, report a possible edge point. M.Nicolescu, UNR
  • 20. Robert Collins CSE486, Penn State Threshold to Find Edge Pixels • Example – cont.: Binary edge image Threshold Mag > 30 M.Nicolescu, UNR
  • 21. Robert Collins Edge Detection Using Gradient Magnitude CSE486, Penn State M.Nicolescu, UNR
  • 22. Robert Collins CSE486, Penn State Issues to Address How should we choose the threshold? > 10 > 30 > 80 M.Nicolescu, UNR
  • 23. Robert Collins Trade-off: Smoothing vs Localization CSE486, Penn State M.Hebert, CMU
  • 24. Robert Collins CSE486, Penn State Issues to Address Edge thinning and linking smoothing+thresholding gives us a binary mask we want thin, one-pixel with “thick” edges wide, connected contours M.Nicolescu, UNR
  • 25. Robert Collins CSE486, Penn State Canny Edge Detector An important case study Probably, the most used edge detection algorithm by C.V. practitioners Experiments consistently show that it performs very well J. Canny A Computational Approach to Edge Detection, IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol 8, No. 6, Nov 1986
  • 26. Robert Collins CSE486, Penn State Formal Design of an Optimal Edge Detector • Edge detection involves 3 steps: – Noise smoothing – Edge enhancement – Edge localization • J. Canny formalized these steps to design an optimal edge detector O.Camps, PSU
  • 27. Robert Collins CSE486, Penn State Edge Model (1D) • An ideal edge can be modeled as an step A  0 if x < 0 G ( x) =   A if x ≤ 0 • Additive, White Gaussian Noise – RMS noise amplitude/unit length no2 O.Camps, PSU
  • 28. Robert Collins CSE486, Penn State Performance Criteria (1) • Good detection – The filter must have a stronger response at the edge location (x=0) than to noise O.Camps, PSU
  • 29. Robert Collins CSE486, Penn State Performance Criteria (2) • Good Localization – The filter response must be maximum very close to x=0 X=0 O.Camps, PSU
  • 30. Robert Collins CSE486, Penn State Performance Criteria (3) • Low False Positives – There should be only one maximum in a reasonable neighborhood of x=0 large O.Camps, PSU
  • 31. Robert Collins CSE486, Penn State Canny Edge Detector • Canny found a linear, continuous filter that maximized the three given criteria. • There is no closed-form solution for the optimal filter. • However, it looks VERY SIMILAR to the derivative of a Gaussian.
  • 32. Robert Collins CSE486, Penn State Recall: Practical Issues for Edge Detection Thinning and linking Choosing a magnitude threshold OR Canny has good answers to all!
  • 33. Robert Collins CSE486, Penn State Thinning note: do thinning before thresholding! mag(x0) = maximum magnitude x0 location along slice We want to mark points along curve where the magnitude is largest. We can do this by looking for a maximum along a 1D intensity slice normal to the curve (non-maximum supression). These points should form a one-pixel wide curve.
  • 34. Robert Collins CSE486, Penn State Which Threshold to Pick? Two thresholds applied to gradient magnitude problem: •If the threshold is too high: –Very few (none) edges •High MISDETECTIONS, many gaps •If the threshold is too low: –Too many (all pixels) edges •High FALSE POSITIVES, many extra edges
  • 35. Robert Collins SOLUTION: Hysteresis Thresholding CSE486, Penn State Allows us to apply both! (e.g. a “fuzzy” threshold) •Keep both a high threshold H and a low threshold L. •Any edges with strength < L are discarded. •Any edge with strength > H are kept. •An edge P with strength between L and H is kept only if there is a path of edges with strength > L connecting P to an edge of strength > H. •In practice, this thresholding is combined with edge linking to get connected contours
  • 36. Robert Collins CSE486, Penn State Example of Hysteresis Thresholding M.Hebert, CMU
  • 37. Canny Edges: Examples Robert Collins CSE486, Penn State Forsyth and Ponce
  • 38. Robert Collins CSE486, Penn State fine scale high threshold Forsyth and Ponce
  • 39. Robert Collins CSE486, Penn State coarse scale, high threshold Forsyth and Ponce
  • 40. Robert Collins CSE486, Penn State coarse scale low threshold Forsyth and Ponce
  • 41. Robert Collins CSE486, Penn State Complete Canny Algorithm See textbook for more details. M.Hebert, CMU