Edge Detection FPCV-2-1
Edge Detection FPCV-2-1
Edge Detection FPCV-2-1
Shree K. Nayar
Monograph: FPCV-2-1
Module: Features
Series: First Principles of Computer Vision
Computer Science, Columbia University
FPCV Channel
FPCV Website
First Principles of Computer Vision Edge Detection
Edge Detection
Edge Detection Convert a 2D image into a set of points where
image intensity changes rapidly.
In this lecture, we will discuss the detection of edges in an image. From the perspective of information
theory, edges are critical to computer vision. An edge can be loosely defined as any location where there
is a rapid change in image intensity along one direction.
We will begin by looking at the physical phenomena that give rise to edges, the attributes of an edge
that we would like to compute, and the performance criteria that a good edge detector should satisfy.
Next, we will develop a theoretical framework for edge detection. We will construct an edge detector
that is based on the gradient operator, which uses the first derivatives of an image. Then, we will look at
edge detection using the Laplacian operator, which uses the second derivatives of the image. We will
examine the advantages and disadvantages of the gradient operator and Laplacian operator. That will
lead us to the widely used Canny edge detector, which uses the best attributes of both of these detectors
to create a reliable and powerful edge detector.
Finally, we will look at the problem of corner detection. A corner is defined as any location where two
edges meet at an angle. We want to be able to find the precise location of the corner without needing
to know the intensity values on either side of the corner or the angle at which the edges meet. We will
describe the Harris corner detector, which is widely used.
FPCV-2-1 1
First Principles of Computer Vision Edge Detection
What is an Edge?
What is an Edge? Rapid change in image intensity within small region
Shree K. Nayar
Columbia University
I.1
3 4
Loosely speaking, we can define an edge as a rapid change in image intensity within a small window in
an image. Let us take a look at why edges are crucial in computer vision. Here is an example from Vic
Nalwa's book. On the left is a photograph of a sculpture by Henry Moore, and on the right is an artist’s
sketch of the sculpture. With just a few strokes, the artist is able to convey essential information about
the sculpture — its three-dimensional structure, its shading, its highlights, and so on. From this example,
we can see that edges, even when sparse in an image, are capable of conveying vital visual information.
made of the same material, if they have different Surface Reflectance Discontinuity
FPCV-2-1 2
First Principles of Computer Vision Edge Detection
FPCV-2-1 3
First Principles of Computer Vision Edge Detection
1D Edge Detection
Edge Detection Using Gradients Edge is a rapid change in image intensity in a small region.
Edge Edge
Topic: Edge Detection, Module: Features
First Principles of Computer Vision
9 10
The first edge detector we will discuss, the gradient operator, is based on the first derivatives of the
image. Let us start with a simple example of a 1D signal, 𝑓(𝑥). We know that an edge is a rapid change
in image intensity within a small region. Shown here is a rising edge on one side and a falling edge on
the other. Calculus tells us that the derivative of a continuous function represents the amount of change
in the function, and change is what we are trying to measure. Thus, it makes sense for us to find the first
derivative of this function and see what that does to both the edges.
FPCV-2-1 4
First Principles of Computer Vision Edge Detection
Edge
12
non-zero value for the 𝑥 component and zero for the %&
%(
𝑦 component as there is no change along the 𝑦 )* )* )* )*
#! = )+ , 0 #! = 0, ), #! = )+ , ),
direction. For the second image, we get zero for the 13
FPCV-2-1 5
First Principles of Computer Vision Edge Detection
14
We can compute the two derivatives using convolutions with the two kernels (filters) shown below. Here,
the “flips” that are needed for each convolution have already been applied. Even if we do not know the
physical distance, ε, between adjacent pixels, it does not matter — the resulting derivatives will simply
be scaled by an unknown factor that is the same for both components and for all pixels in the image.
Once we have computed the two components of the gradient, we use them to find the magnitude and
the orientation of the edge as previously discussed. If ε is unknown, the computed magnitude will simply
be a scaled version of the true value.
FPCV-2-1 6
First Principles of Computer Vision Edge Detection
on the left. In this case, note that the derivatives !" !$ # $ "
!" !$ # $ "
Sobel operator was popular for a long time. We Good Localization Poor Localization
can see that these operators are getting larger as Noise Sensitive
Poor Detection
Less Noise Sensitive
Good Detection 16
we move from left to right. When we have a small
operator, we can expect very good localization for the edges, as small operators will not be affected by
image content that is far away from the pixel of interest. On the other hand, a small detector is bound
to be extremely sensitive to noise. In the case of the Roberts detector, since only four numbers are being
used to determine whether a point has an edge, if noise corrupts even one of these four numbers, the
computed derivatives will have large errors.
Looking at the larger operators, we can see that these can be viewed as just the smaller operators
convolved with a smoothing function like a Gaussian. In effect, smoothing is being incorporated into the
derivative operators to reduce the effect of noise. Therefore, the larger operators have much better
noise resilience. However, they have poor localization, because if we are trying to find an edge at a pixel,
the derivatives computed are going to be influenced by image content that is far from the pixel. This is
not a problem if the edge continues to be an edge over the entire extent of the operator, but if the edge
turns into something else, or new information appears, the output of the operator will be affected.
FPCV-2-1 7
First Principles of Computer Vision Edge Detection
thresholding, by using two thresholds. We declare #$(&, () < !! Definitely Not an Edge
no edge if the magnitude is less that the lower #$(&, () ≥ !" Definitely an Edge
threshold, and an edge if it is greater than the !! ≤ #$(&, () < !" Is an Edge if a Neighboring Pixel
is Definitely an Edge
higher threshold. If the magnitude lies between 18
the two thresholds, we can make a decision based
on the how “edgy” the neighboring pixels are.
FPCV-2-1 8
First Principles of Computer Vision Edge Detection
Shree K. Nayar
%! Local Extrema
Columbia University First Derivative: Indicate Edges
%#
%&! Zero-Crossings
Second Derivative:
%# & Indicate Edges
20 21
Now let’s look at how we can use the second derivative of an image to detect edges. That brings us to
the Laplacian operator. Once again, we will start with our 1D signal, 𝑓(𝑥), and its first derivative, which
we already know. The question is, what is the derivative of the derivative, which would be the second
derivative? Let us consider the rising edge shown here. We know that where the first derivative is
increasing, the second derivative will have positive values, and where the first derivative is decreasing,
it will have negative values. In between, when the first derivative reaches a peak, the second derivative
will be zero. Therefore, exactly at the location of the edge, we get a sharp change from positive to
negative values, called a zero-crossing. In the case of the falling edge on the right, we get exactly the
flipped version of the second derivative of the rising edge. Therefore, edge detection boils down to
finding sharp zero-crossings in the second derivative.
FPCV-2-1 9
First Principles of Computer Vision Edge Detection
This operator works fine. However, there is a slight problem that arises from the fact that pixels on an
image sensor lie on a square grid. We have found the second derivatives with respect to 𝑥 and 𝑦,
assuming that the distance between adjacent pixels is ε. Now, let us say an edge appears at 45 degrees.
In that case, we see that we have not taken into account the fact that the distance between pixels in the
diagonal direction is greater than ε. In order to account for this variability, we can consider edges in a
few difference orientations, develop convolution masks for each one, and then average the masks to
end up with the one shown on the right. The output of this operator is less sensitive to the orientation
of the edge and hence it is widely used.
FPCV-2-1 10
First Principles of Computer Vision Edge Detection
at the edge.
FPCV-2-1 11
First Principles of Computer Vision Edge Detection
edge.
# 1 05 ∗ /
28
FPCV-2-1 12
First Principles of Computer Vision Edge Detection
orientation, whereas the Laplacian operator is a single convolution which is a linear operation. These
differences between the two operators are subtle and may not be critical in most applications. The more
important question is whether we can come up with an edge detector that exploits the best
characteristics of both of these operators and works better than either one of them.
31
#05 ∗ ! *
+ #05 ∗ !
2=
3 2=
3
#05 ∗ ! #05 ∗ !
• Compute Laplacian along the Gradient • Compute Laplacian along the Gradient
Direction +
* at each pixel Direction +
* at each pixel
' 1 05 ∗ ! ' 1 05 ∗ !
31
'2 #05 ∗ ! 31
'2 #05 ∗ !
• Find Zero Crossings in Laplacian to find
[Canny 1986] 32 the edge location [Canny 1986] 33
First, we smooth the input image with a Gaussian of width 𝜎. Then, we apply the gradient operator (for
instance, the 3x3 Sobel operator) to the smoothed image to get two numbers at each pixel — the
derivatives in the 𝑥 and 𝑦 directions. From these, we can compute the magnitude and the orientation of
the gradient at each pixel. The magnitude is what is being shown in the image here; the brighter the
point, the greater the magnitude.
Next, at each pixel, a 1D Laplacian (second derivative) is applied along the gradient direction at the pixel.
If a zero-crossing is detected, then an edge is declared at the location of the zero-crossing. The advantage
of applying a 1D Laplacian along the gradient direction is that it is less effected by pixels that are
unrelated to the edge. In the image in the slide on the right, the highlighted pixels correspond to the
detected zero-crossings (edges).
FPCV-2-1 13
First Principles of Computer Vision Edge Detection
Next, let us take a look at a couple of illusions associated with edges. Below is the Hering Illusion. We
can all agree that, in the slide on the left, the two horizontal lines appear to be bulging out. Now, if we
remove all of the other lines in the image (right slide), we see that the two lines are perfectly straight
and parallel to each other. The reason this happens is that when there are acute angles in an image, the
human visual system tends to see these as less acute angles. As a result, the acute angles made by these
two lines with respect to the other lines (spokes) in the original image (left slide) are overestimated such
that the error increases with the acuteness of the angle. This bias makes us believe that the two
horizontal lines are curved lines when they are not.
I.4 I.4
35 36
EYE AND BRAIN EYE AND BRAIN
FPCV-2-1 14
First Principles of Computer Vision Edge Detection
I.5
37
EYE AND BRAIN
38
EYE AND BRAIN
Corners
Corner Detection Corner: Point where Two Edges Meet. i.e., Rapid Changes
of Image Intensity in Two Directions within a Small Region
Shree K. Nayar
Columbia University
39 40
Let us now talk about how we can find corners in an image. On the right, we see three image regions –
a flat region, an edge region and a corner region. A corner is essentially a point where two edges meet.
Unlike an edge where we have a rapid change in image intensity along one direction, in this case, if we
FPCV-2-1 15
First Principles of Computer Vision Edge Detection
place a window around the corner, we are going to see a rapid change in image intensity along two
directions. As in the case of edge detection, we are going to use the derivatives of the image to perform
corner detection.
FPCV-2-1 16
First Principles of Computer Vision Edge Detection
1& 1# 1# 1&
1#
1& &* &* &*
best fits the binary object. We will say that the Maximum Moment of Inertia = :+,*
Minimum Moment of Inertia = :+!-
length 𝜆# of the semi-major axis of the ellipse is (See lecture on Binary Images)
b, and c. From these three numbers, we can (See lecture on Binary Images)
compute the maximum second moment Emax, and Ellipse Axes Lengths:
distribution.
FPCV-2-1 17
First Principles of Computer Vision Edge Detection
FPCV-2-1 18
First Principles of Computer Vision Edge Detection
means that one or more pixels within the window Used for finding Local Extrema (Maxima/Minima)
49
have larger values, then it is either suppressed
(reduced in value), or eliminated completely (set to zero). If suppression is used, the method will need
to be applied repeatedly until the peaks are the only locations with non-zero values.
R value are retained if they are above the Image Corner Response "
FPCV-2-1 19
First Principles of Computer Vision Edge Detection
I.7
Kitaoka, 1998
EYE AND BRAIN 52
something — the bulge — that does not exist. EYE AND BRAIN
Kitaoka, 1998
53
FPCV-2-1 20
First Principles of Computer Vision Edge Detection
References: Textbooks
54 55
[Nalwa 1986] Nalwa, V. S. and Binford, T. O., “On detecting edges,” Mathworks.
IEEE Trans. Pattern Analysis and Machine Intelligence, 1986. I.7 A. Kitaoka. Used with permission.
56 57
Acknowledgements: Thanks to Nisha Aggarwal and Jenna Everard for their help with transcription,
editing and proofreading.
FPCV-2-1 21