7 Edge Detection
7 Edge Detection
Edge Detection
• Interested in three types of image features
• Isolated points
• Lines
• Edges
Some Common Terms
• Edge Pixels: Pixels at which the intensity of an image function
changes abruptly.
• Edges: Set of connected edge pixels.
• Edge Detectors: local image processing methods designed to detect
edge pixels.
• Line: an edge segment in which the intensity of the background on
either side of line is much higher or much lower than the intensity of
line pixels.
• Isolated points: a line whose length and width is equal to one pixel.
Background
• Averaging (smoothing) is analogous to integration.
• Sharpening could be accomplished by differentiation
• Derivatives of a digital function are defined in terms of differences.
• First Order Derivative:
• Must be zero in the areas of constant intensity
• Must be nonzero at the onset of a gray-level step or ramp; and
• Must be nonzero along ramps.
• A basic definition of the first-order derivative of a one-dimensional function
f(x) is
𝜕𝑓
= 𝑓 𝑥 + 1 − 𝑓(𝑥)
𝜕𝑥
• Second Order Derivative:
• Must be zero in the areas of constant intensity
• Must be nonzero at the onset and end of a gray-level step or ramp;
• Must be zero along ramps of constant slope
• We define a second-order derivative as the difference
𝜕2𝑓
2
= 𝑓 𝑥 + 1 + 𝑓 𝑥 − 1 − 2𝑓(𝑥)
𝜕𝑥
Edge Detection
• First order derivatives produce thick edges while second order derivatives
produce finer ones. (See ramp edge on previous slide)
• Second order derivatives enhance sharp changes and fine details more
aggressively than first order derivatives (see the isolated point and the line
in the same figure). This can be a problem if the noise is present in the
image
• Second derivative changes its sign as it transitions into and out of a ramp or
step edge. See the step edge. This “double edge” effect can be used to
locate edges.
• The sign of the second derivative is also used to determine whether an
edge is a transition from light to dark (-ve value) or from dark to light (+ve
value). See step edge
Edge Detection
• Spatial filters are used to compute first and second order derivatives
at each pixel location.
• Compute the sum of products of mask coefficients with intensity
values encompassed by the mask.
A general 3x3 spatial filter mask
• The response of mask at center point is
𝑅 = 𝑤1𝑧1 + 𝑤2𝑧2 + ⋯ + 𝑤9𝑧9 w1 w2 w3
9
w4 w5 w6
𝑅 = 𝑤𝑘 𝑧𝑘
𝑘=1 w7 w8 w9
Detection of Isolated Points
Detection of Isolated Points
• Point detection should be based on second derivative.
𝛻2𝑓
= 𝑓 𝑥 + 1, 𝑦 + 𝑓 𝑥 − 1, 𝑦 + 𝑓 𝑥, 𝑦 + 1 + 𝑓 𝑥, 𝑦 − 1 − 4𝑓 𝑥, 𝑦
1 1 1
1 -8 1
1 1 1
Detection of Isolated Points
• A point has been detected at location (x, y) on which the mask is
centered if the absolute value of response of the mask at that point
exceeds a specified threshold.
• Such points are labelled 1 in the output image and all others are
labelled 0.
1 𝑖𝑓 𝑅(𝑥, 𝑦) ≥ 𝑇
𝑔 𝑥, 𝑦 =
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Line Detection
Line Detection
• For line detection we can expect second order derivatives to result in
a stronger response and to produce thinner lines than first order
derivatives.
Original Image Laplacian Image
Positive values of
Absolute value of Laplacian
Laplacian
0 1 1 0
Gradient Operators
• Use of masks/filters that are symmetric about the center point
• The smallest filter mask should be 3x3.
• The difference between the third and first rows of the 3x3 mage
region approximate derivative in x-direction, and the difference
between the third and first column approximate derivative in y-
direction.
gx= 𝑧7 + 𝑧8 + 𝑧9 − 𝑧1 + 𝑧2 + 𝑧3
gy= 𝑧3 + 𝑧6 + 𝑧9 − (𝑧1 + 𝑧4 + 𝑧7)
Some common gradient operators
2 in the center
location provides the
image smoothing