Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge...
Transcript of Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge...
![Page 1: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/1.jpg)
Edge Detection
Dr. Mongkol Ekpanyapong
![Page 2: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/2.jpg)
2
Roadmap• Introduction to image analysis (computer vision)
– Its connection with psychology and neuroscience
– Why is image analysis difficult?
• Theory of edge detection
– Gradient operator
– Advanced operators
• Applications
– Road/sign detection in intelligent driving systems
– Pupil detection in iris recognition systems
![Page 3: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/3.jpg)
3
Computer Vision: the Grand Challenge
• Teach a computer to see is nontrivial at all
• Unlike binary images, grayscale/color images
acquired by the sensor are often easy to
understand by human being but difficult for a
machine or a robot
• There are lots of interesting problems in the field
of computer vision (image analysis)
– Image segmentation, image understanding,
face detection/recognition, object tracking …
![Page 4: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/4.jpg)
4
How does Human Vision System work?
Top-down school Bottom-up school
pixels
objects
components (such as
edges, lines etc.)
I see a human body
I expect to see a human face
I expect to see two eyes and a nose
Two hypothesis and nobody knows the answer yet!
![Page 5: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/5.jpg)
5
An Amazing Image Example
Person A:
I see an old man with a fancy
earring and a strange hand
Person B:
I see two people on the street
and a dog lying beside
If you try really hard, you will be able
to locate at least eight different faces
from this image
![Page 6: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/6.jpg)
6
Gestalt Theory (the Berlin School)
Emergence: the dog is perceived as a whole, all at once
![Page 7: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/7.jpg)
7
Reification
![Page 8: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/8.jpg)
8
Multistability (or Multistable Perception)
![Page 9: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/9.jpg)
9
Invariance
![Page 10: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/10.jpg)
10
Application: Face Detection
http://vasc.ri.cmu.edu/demos/faceindex/
You are strongly encouraged to try the interactive demo out yourself
![Page 11: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/11.jpg)
Image Segmentation
• Segmentation subdivides an image into its
constituent regions or objects
• Some examples are point, line, and edge
detection
![Page 12: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/12.jpg)
Point Detection
• Using the mask below, we say that an
isolated point has been detected at the
location on which the mark is centered if
|R| T when T is non negative threshold
![Page 13: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/13.jpg)
Matlab Function
f=imread('sphere.tif');
w = [ -1 -1 -1 ; -1 8 -1; -1 -1 -1];
g = abs(imfilter(double(f),w)) ;
g = g >= 15;
imshow(f);
figure, imshow(g)
![Page 14: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/14.jpg)
Result
![Page 15: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/15.jpg)
15
Edge Detection
• Why detect edge?
Edges characterize object boundaries and are
useful features for segmentation, registration
and object identification in scenes.
• What is edge (to human vision system)?
Intuitively, edge corresponds to singularities in the image
(i.e. where pixel value experiences abrupt change)
No rigorous definition exists
![Page 16: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/16.jpg)
Line Detection
• Let R1, R2, R3, and R4 denote the responses of the
masks below
• Suppose that the four masks are run individually
through an image, if |Ri| > |Rj| then the point is
more likely associated with a line in the direction i
![Page 17: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/17.jpg)
Example
![Page 18: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/18.jpg)
Edge detection is a hard image
processing problem
• Most edge detection solutions exhibit limited
performance in the presence of images
containing real-world scenes.
• It is common to precede the edge detection
stage with pre-processing operations such as
noise reduction and illumination correction
![Page 19: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/19.jpg)
Edge Detection
• Edge model
– Step edge
– Ramp edge
– Roof edge
![Page 20: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/20.jpg)
Basic concepts• Edge: a boundary between two image regions having
distinct characteristics according to some feature (e.g., gray level, color, or texture).
• In grayscale 2D images: a sharp variation of the intensity function across a portion of the image.
![Page 21: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/21.jpg)
Basic concepts
• Edge detection methods usually rely on calculations of the first or second derivative along the intensity profile.
– The magnitude of the first derivative can be used to detect the presence of an edge at a certain point in the image.
– The sign of second derivative can be used to determine whether a pixel lies on the dark or bright side of an edge.
– Moreover, the zero crossing between its positive and negative peaks can be used to locate the center of thick edges.
![Page 22: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/22.jpg)
Basic concepts
• First and
second
derivative
![Page 23: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/23.jpg)
Basic concepts
• The
influence
of noise
![Page 24: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/24.jpg)
Intensity profile of the edge with noise
![Page 25: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/25.jpg)
Intensity profile of the edge
![Page 26: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/26.jpg)
Basic concepts
• The process of edge detection consists
of three main steps:
– Noise reduction
– Detection of edge points
– Edge localization
• In MATLAB: edge
![Page 27: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/27.jpg)
27
Gradient Operators
• Motivation: detect changes
change in the pixel value large gradient
Gradient
operatorimage Thresholding
edge
mapx(m,n) g(m,n) I(m,n)
otherwise
thnmgnmI
0
|),(|1),(
MATLAB function: > help edge
![Page 28: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/28.jpg)
Basic Edge Detection
• We know that we can find edge by using
first and second derivative
• The magnitude is
• The direction is
![Page 29: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/29.jpg)
Gradient Vector
Grey pixel = 0, and white pixel = 1, using 3x3 neighborhood
From the picture gx = -2 (downward direction)
gy = 2
Magnitude = 22 and angle = 145 degree
![Page 30: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/30.jpg)
Gradient Operator
• Obtaining the gradient of an image
requires the partial derivative
simplified version (no square root)
![Page 31: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/31.jpg)
One Dimension Mark
• Only use to present conceptually
gx
gy
![Page 32: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/32.jpg)
Image Neighborhood
![Page 33: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/33.jpg)
Simple 3x3 mask
![Page 34: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/34.jpg)
First-order derivative edge detection
• Prewitt operators:
![Page 35: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/35.jpg)
First-order derivative edge detection
• Prewitt operator
![Page 36: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/36.jpg)
36
Examples
horizontal edge vertical edge
Prewitt operator
original image
![Page 37: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/37.jpg)
37
Effect of Thresholding Parameters
thresholdsmall large
![Page 38: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/38.jpg)
38
Compass Operators
101
101
101
111
000
111
111
000
111
101
101
101
110
101
011
110
101
011
011
101
110
011
101
110
|}),({|max),( nmgnmg kk
![Page 39: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/39.jpg)
39
Examples
Compass operator
![Page 40: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/40.jpg)
Sobel Edge Detector
• The idea is to give more emphasis to on-
axis pixels
![Page 41: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/41.jpg)
First-order derivative edge detection
• Sobel operators:
![Page 42: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/42.jpg)
First-order derivative edge detection
• Sobel operator
![Page 43: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/43.jpg)
2-dimension mark
![Page 44: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/44.jpg)
2-dimension mark
![Page 45: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/45.jpg)
Original Image
![Page 46: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/46.jpg)
Different Edge Detection
b) gx c) gy d) |gx|+|gy|
![Page 47: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/47.jpg)
![Page 48: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/48.jpg)
First-order derivative edge detection
• Sobel operator with threshold (example)
SECOND-ORDER DERIVATIVE EDGE DETECTION 315
Figure 14.7 Robinson compass masks.
(a) (b)
(c) (d)
Figure 14.8 Edge detection using Sobel operator and thresholding (the original image is the same
asFigure14.5(a)): (a) Threshold of 0; (b) Threshold of 0.05; (c) Threshold of 0.1138 (thebest value);
(d) Threshold of 0.2.
In MATLAB
Edge detection using the Laplacian operator can be implemented using the f speci al
function (to generate the Laplacian 3⇥3 convolution mask) and the zer ocr oss option in
function edge as follows:
![Page 49: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/49.jpg)
Second-order derivative edge detection
• Second-order derivative
(the Laplacian of an image):
![Page 50: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/50.jpg)
Second-order derivative edge detection
• Laplacian of an image:
• The general version:
![Page 51: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/51.jpg)
Example
![Page 52: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/52.jpg)
52
Laplacian Operators
• Gradient operator: first-order derivative
sensitive to abrupt change, but not slow change
second-order derivative:2
2
2
22
y
f
x
ff
(Laplacian operator)
02
2
x
flocal extreme in f’
010
141
010
111
181
111
• Discrete Laplacian operator
a=0 a=0.5
aaa
aa
aaa
a1
141
1
1
1
![Page 53: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/53.jpg)
53
Zero Crossings
f f’ f’’
zero crossing
Laplacian
operatorimage zero-crossing
edge
mapx(m,n) g(m,n) I(m,n)
![Page 54: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/54.jpg)
54
Examples
zero-crossingsoriginal image
Question: why is it so sensitive to noise (many false alarms)?
Answer: a sign flip from 0.01 to -0.01 is treated the same as from 100 to -100
![Page 55: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/55.jpg)
Second-order derivative edge detection
• Laplacian and
zero-crossa) Input
b) Laplacian
c) Zero crossing
d) Input with noise
e) Laplacian
f) Zero crossing
![Page 56: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/56.jpg)
int main(int argc, char** argv)
{
Mat src = imread("d:/image/cameraman2.tif", IMREAD_GRAYSCALE);
Mat dst, dst2;
Sobel(src, dst, -1, 1, 1);
Laplacian(src, dst2, -1);
// Show the results
namedWindow(" ORIGINAL ", WINDOW_AUTOSIZE);
imshow(" ORIGINAL ", src);
namedWindow(" SOBEL ", WINDOW_AUTOSIZE);
imshow(" SOBEL ", dst);
namedWindow(" LAPLACIAN ", WINDOW_AUTOSIZE);
imshow(" LAPLACIAN ", dst2);
waitKey();
return 0;
}
![Page 57: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/57.jpg)
57
Ideas to Improve Robustness
• Linear filtering
– Use a Gaussian filter to smooth out noise component Laplacian of Gaussian
• Spatially-adaptive (Nonlinear) processing
– Apply different detection strategies to smooth areas (low-variance) and non-smooth areas (high-variance) Robust Laplacian edge detector
• Return single response to edges (not multiple edge pixels)
– Hysteresis thresholding Canny’s edge detector
![Page 58: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/58.jpg)
Second-order derivative edge detection
• Problems with Laplacian:
– It generates “double edges”, i.e.,
positive and negative values for each
edge.
– It is extremely sensitive to noise.
• In MATLAB:
h = fspecial('laplacian',0);
J = edge(I,'zerocross',t,h);
![Page 59: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/59.jpg)
Second-order derivative edge detection
• Laplacian of Gaussian (LoG):
– Works by smoothing the image
with a Gaussian low-pass filter,
and then applying a Laplacian
edge detector to the result.
– The LoG filter can sometimes be
approximated by taking the
differences of two Gaussians of
different widths, in a method
known as Difference of
Gaussians (DoG).
![Page 60: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/60.jpg)
Second-order derivative edge detection
• Laplacian of Gaussian (LoG) transfer function
(Mexican hat) 318 EDGE DETECTION
(a) (b)
(c) (d)
Figure14.10 Laplacian of Gaussian (LoG): (a) 3D plot; (b) 2D intensity plot; (c) cross section of
(a).
2. Thelocal gradient (intensity anddirection) iscomputed for eachpoint in thesmoothed
image.
3. The edge points at the output of step 2 result in wide ridges. The algorithm thins
those ridges, leaving only the pixels at the top of each ridge, in a process known as
non-maximal suppression.
4. The ridge pixels are then thresholded using two thresholds, Tl ow and Thi gh : ridge
pixels with value greater than Thi gh are considered strong edge pixels; ridge pixels
with values between Tl ow and Thi gh are said to be weak pixels. This process is
known as hysteresis thresholding.
5. Thealgorithm performs edge linking, aggregating weak pixels that are8-connected2
to the strong pixels.
In MATLAB
The edge function includes the Canny edge detector, which can be invoked using the
following syntax:
2In someimplementations, only theneighbors along alinenormal to thegradient orientation at theedgepixel are
considered, not the entire 8-neighborhood.
![Page 61: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/61.jpg)
Second-order derivative edge detection
• Laplacian of Gaussian (LoG) transfer function
(2D cross-section of 3D plot) and mask
(kernel)
318 EDGE DETECTION
(a) (b)
(c) (d)
Figure 14.10 Laplacian of Gaussian (LoG): (a) 3D plot; (b) 2D intensity plot; (c) cross section of
(a).
2. Thelocal gradient (intensity anddirection) iscomputed for eachpoint in thesmoothed
image.
3. The edge points at the output of step 2 result in wide ridges. The algorithm thins
those ridges, leaving only the pixels at the top of each ridge, in a process known as
non-maximal suppression.
4. The ridge pixels are then thresholded using two thresholds, Tl ow and Thi gh : ridge
pixels with value greater than Thi gh are considered strong edge pixels; ridge pixels
with values between Tl ow and Thi gh are said to be weak pixels. This process is
known as hysteresis thresholding.
5. Thealgorithm performs edge linking, aggregating weak pixels that are8-connected2
to the strong pixels.
In MATLAB
The edge function includes the Canny edge detector, which can be invoked using the
following syntax:
2In some implementations, only theneighborsalong alinenormal to thegradient orientation at theedgepixel are
considered, not the entire 8-neighborhood.
318 EDGE DETECTION
(a) (b)
(c) (d)
Figure 14.10 Laplacian of Gaussian (LoG): (a) 3D plot; (b) 2D intensity plot; (c) cross section of
(a).
2. Thelocal gradient (intensity anddirection) iscomputed for eachpoint in thesmoothed
image.
3. The edge points at the output of step 2 result in wide ridges. The algorithm thins
those ridges, leaving only the pixels at the top of each ridge, in a process known as
non-maximal suppression.
4. The ridge pixels are then thresholded using two thresholds, Tl ow and Th i gh : ridge
pixels with value greater than Th i gh are considered strong edge pixels; ridge pixels
with values between Tl ow and Th i gh are said to be weak pixels. This process is
known as hysteresis thresholding.
5. Thealgorithm performsedge linking, aggregating weak pixels that are8-connected2
to the strong pixels.
In MATLAB
The edge function includes the Canny edge detector, which can be invoked using the
following syntax:
2In some implementations, only theneighbors along aline normal to thegradient orientation at theedgepixel are
considered, not the entire 8-neighborhood.
![Page 62: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/62.jpg)
![Page 63: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/63.jpg)
63
Laplacian of Gaussian
• Generalized Laplacian operator
)2
exp(])(
1[),(2
22
2
22
nmnmcnmh
Laplacian
operatorimage edge
mapx(m,n) g(m,n) I(m,n)
Gaussian
LPF ()
Pre-filtering: attenuate the noise sensitivity of the Laplacian
![Page 64: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/64.jpg)
64
Examples
Better than Laplacian alone but still sensitive due to zero crossing
![Page 65: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/65.jpg)
65
Robust Laplacian-based Edge Detector
Laplacian
operatorimage zero
crossing?
estimate
local variance
2>th
2
not an
edge point
No
yes
No
not an
edge point
edge
point
![Page 66: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/66.jpg)
66
Examples
More robust but return multiple edge pixels (poor localization)
![Page 67: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/67.jpg)
Canny Edge Detector
Canny edge approach is based on 3 objectives:
• Low error rate: all edges should be found
• Edge points should be well localized: the edges
located must be as close as possible to true
edges
• Single edge point response: should return only
one point for each true edge point
![Page 68: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/68.jpg)
68
Flow-chart of Canny Edge Detector*(J. Canny’1986)
Original image
Smoothing by Gaussian convolution
Differential operators along x and y axis
Non-maximum suppression
finds peaks in the image gradient
Hysteresis thresholding locates edge strings
Edge map
![Page 69: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/69.jpg)
The Canny edge detector1. The input image is smoothed using a Gaussian low pass filter
(LPF), with a specified value of σ.
2. The local gradient (intensity and direction) is computed for each point in the smoothed image.
3. The edge points at the output of step 2 result in wide ridges. The algorithm thins those ridges, leaving only the pixels at the top of each ridge (non-maximal suppression).
4. The ridge pixels are then thresholded using two thresholds, Tlowand Thigh: ridge pixels with value greater than Thigh are considered strong edge pixels; ridge pixels with values between Tlow and Thigh are said to be weak pixels. This process is known as hysteresis thresholding.
5. The algorithm performs edge linking, aggregating weak pixels that are 8-connected to the strong pixels.
In MATLAB: J = edge(I, 'canny', T, sigma);
![Page 70: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/70.jpg)
70
Canny Edge Detector Example
original image vertical edges horizontal edges
norm of the gradient after thresholding after thinning
![Page 71: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/71.jpg)
Compute Image gradient
![Page 72: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/72.jpg)
Example
![Page 73: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/73.jpg)
![Page 74: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/74.jpg)
void CannyThreshold(int, void*){
blur(src, detected_edges, Size(3, 3));
Canny(detected_edges, detected_edges, lowThreshold, lowThreshold*ratio,
kernel_size);
dst = Scalar::all(0);
src.copyTo(dst, detected_edges);
imshow(window_name, dst);
}
int main(int argc, char** argv){
src = imread("d:/image/cameraman2.tif", IMREAD_GRAYSCALE);
dst.create(src.size(), src.type());
namedWindow(window_name, CV_WINDOW_AUTOSIZE);
createTrackbar("Min Threshold:", window_name, &lowThreshold,
max_lowThreshold, CannyThreshold);
CannyThreshold(0, 0);
waitKey(0);
return 0;
}
![Page 75: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/75.jpg)
The Canny edge detector
(a) default values (σ = 1,
Tflow = 0.0625,
Thigh = 0.1563);
(b) σ = 0.5;
(c) σ = 2;
(d) σ = 1,
Tflow = 0.01,
Thigh = 0.1.
![Page 76: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/76.jpg)
76
Edge Detection in Iris Image
>I=imread(‘'ris.bmp');
>c=edge(I, 'canny');
>[x,y]=find(c==1);
![Page 77: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/77.jpg)
Edge linking and boundary detection
• Goal of edge detection: to produce an image containing only the edges of the original image.
• However, due to the many technical challenges (noise, shadows, occlusion, etc,), most edge detection algorithms will output an image containing fragmented edges.
• Additional processing is needed to turn fragmented edge segments into useful lines and object boundaries.
• Hough transform: a global method for edge linking and boundary detection.
![Page 78: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/78.jpg)
The Hough transform
• A mathematical method designed to find
lines in images.
– It can be used for linking the results of edge
detection, turning potentially sparse, broken,
or isolated edges into useful lines that
correspond to the actual edges in the image.
![Page 79: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/79.jpg)
The Hough transform• Let (x,y) be the coordinates of a point in a binary image (containing
thresholded edge detection results).
• The Hough transform stores in an accumulator array all pairs (a,b) that
satisfy the equation y = ax+ b. The (a,b) array is called the transform
array.
– Example:, the point (x,y) = (1,3) in the input image will result in the equation
b = -a + 3, which can be plotted as a line that represents all pairs (a,b) that
satisfy this equation.
![Page 80: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/80.jpg)
The Hough transform• Since each point in the image will map to a line in the transform
domain, repeating the process for other points will result in many
intersecting lines, one per point.
• The meaning of two or more lines intersecting in the transform domain
is that the points to which they correspond are aligned in the image.
• The points with the greatest number of intersections in the transform
domain correspond to the longest lines in the image.
![Page 81: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/81.jpg)
Line Detection using Hough Transform
• Consider a line that passes through points
(xi,yi) and (xj,yj)
• The line equation can be written as:
yi = a xi + b and yj = a xj + b
• We can also write
b = -xi a + yi and b = -xj a + yj
![Page 82: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/82.jpg)
Example
![Page 83: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/83.jpg)
Concept• The parameter-space lines corresponds to all
point (xk,yk) in the xy plane could be plotted.
• Lines in the plane could be found by identifying
points in parameter space where large number
of lines intersect ( b = -xi a + yi )
• However, a (slope of the line) can approach
infinity when we approach the vertical direction
• One way around is to use: x cos + y sin =
![Page 84: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/84.jpg)
Sinusoidal curves
![Page 85: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/85.jpg)
Example
![Page 86: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/86.jpg)
Hough Transform Peak Detection
![Page 87: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/87.jpg)
Example
![Page 88: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/88.jpg)
OpenCV
![Page 89: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/89.jpg)
The Hough transform• Coordinate conversion
– Describing lines using the equation y = ax
+ b (where a represents the gradient)
poses a problem, though, since vertical
lines have infinite gradient.
• This limitation can be circumvented by
using the normal representation of a
line, which consists of two parameters:
ρ and θ.
• In this new representation, vertical
lines will have θ = 0.
• It is common to allow ρ to have
negative values, therefore restricting θ
to the range −90◦ < θ ≤ 90◦.
![Page 90: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/90.jpg)
The Hough transform
• Under the new set of coordinates, the Hough transform
can be implemented as follows:
1. Create a 2D array corresponding to a discrete set of
values for ρ and θ. Each element in this array is often
referred to as an accumulator cell.
2. For each pixel (x,y) in the image and for each chosen
value of θ, compute x cos θ + y sin θ and write the
result in the corresponding position (ρ, θ) in the
accumulator array.
3. The highest values in the (ρ, θ) array will correspond
to the most relevant lines in the image.
![Page 91: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/91.jpg)
int main(int argc, char** argv){
Mat src = imread("d:/image/checkerboard.png",
IMREAD_GRAYSCALE);
Mat dst, cdst;
Canny(src, dst, 50, 200, 3);
cvtColor(dst, cdst, CV_GRAY2BGR);
vector<Vec4i> lines;
HoughLinesP(dst, lines, 1, CV_PI / 180, 50, 50, 10);
for (size_t i = 0; i < lines.size(); i++){
Vec4i l = lines[i];
line(cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 0, 255), 3,
CV_AA);
}
imshow("source", src);
imshow("detected lines", cdst);
waitKey(0);
}
![Page 92: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/92.jpg)
The Hough transform
• Example 14.6EDGE LINKING AND BOUNDARY DETECTION 323
(a)
(b)
Figure 14.16 Hough transform example: (a) input image; (b) results of Hough Transform,
highlighting the intersections corresponding to the predominant lines in the input image.
in theHough transform results, where k ispassed asaparameter) and houghl i nes, which
draws the lines associated with the highest peaks on top of the original image.
EXAMPLE 14.7
In this example we use hough, houghpeaks, and houghl i nes on a grayscale test
image whose edges havebeen extracted using the Canny edge detector5.
Figure 14.17(a) shows the results of the Hough transform calculations with two
small squares indicating the two highest peaks. Figure 14.17(b) shows the result of
theCanny edge detector (displayed with black pixels against awhite background for
better visualization). Figure 14.17(c) displays the original image with the highest
(cyan) and second highest (yellow) lines overlaid.
The Hough transform can be extended and generalized to find other shapes in images.
Please refer to the “Learn more about it” section at the end of the chapter for useful
references.
5The complete sequence of MATLAB commands is available at the book web site.
EDGE LINKING AND BOUNDARY DETECTION 323
(a)
(b)
Figure 14.16 Hough transform example: (a) input image; (b) results of Hough Transform,
highlighting the intersections corresponding to the predominant lines in the input image.
in theHough transform results, wherek ispassed asaparameter) and houghl i nes, which
draws the lines associated with the highest peaks on top of the original image.
EXAMPLE 14.7
In this example we use hough, houghpeaks, and houghl i nes on a grayscale test
image whose edges havebeen extracted using the Canny edge detector5.
Figure 14.17(a) shows the results of the Hough transform calculations with two
small squares indicating the two highest peaks. Figure 14.17(b) shows the result of
the Canny edgedetector (displayed with black pixelsagainst awhite background for
better visualization). Figure 14.17(c) displays the original image with the highest
(cyan) and second highest (yellow) lines overlaid.
The Hough transform can be extended and generalized to find other shapes in images.
Please refer to the “Learn more about it” section at the end of the chapter for useful
references.
5The complete sequence of MATLAB commands is available at the book web site.
![Page 93: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/93.jpg)
The Hough transform
• In MATLAB:
– The IPT also includes two useful companion
functions for exploring and plotting the results
of Hough Transform calculations:
•houghpeaks: identifies the k most salient peaks in
the Hough transform results, where k is passed as
a parameter.
•houghlines: draws the lines associated with the
highest peaks on top of the original image.
![Page 94: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/94.jpg)
The Hough transform
![Page 95: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/95.jpg)
95
Line/Polynomial Fitting
y=ax+b y=ax2+bx+c
x
y
x
y
MATLAB function: P = POLYFIT(X,Y,N)
Polynomial of degree N
![Page 96: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/96.jpg)
Analytical vs. Numerical
Solutions
96
23)( 2 xxxf
2,1 21 xxTwo roots:
)(3
2023)(
22 xg
xxxxxf
3
22
1
ii
xxsuccessive substitution:
Analytical
Numerical
![Page 97: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/97.jpg)
97
Basic Idea Behind
x
y
?
Question: Can we find a transform that maps a line to a point?
![Page 98: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/98.jpg)
98
Radon/Hough Transform:
Mathematics*
• (x1y1)
Two of an infinite numberof lines through point (x1,y1) - Space
min max
min
max
•
•
Sample oftwo lines
![Page 99: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/99.jpg)
99
Generalizations of Hough Transform
(from 2D to N-D)
Analytic Form Parameters Equation
Line , xcos+ysin=
Circle x0, y0, (x-xo)2+(y-y0)
2=r2
Parabola x0, y0, , (y-y0)2=4(x-xo)
Ellipse x0, y0, a, b, (x-xo)2/a2+(y-y0)
2/b2=1
![Page 100: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/100.jpg)
100
Radon/Hough Transform: Image
Examples
Conclusion: Line detection can be implemented by point (peak)
detection in the Radom/Hough transform domain
![Page 101: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/101.jpg)
101
Line Detection from Real-world
Images
Gray Scale Image Edge Image (Canny)
![Page 102: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/102.jpg)
102
Peak Finding
![Page 103: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/103.jpg)
Application in Computer
Tomography*
(From Jain’s Fig.10.1)
![Page 104: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/104.jpg)
104
Beyond Edge Detection• Edges are among the earliest primitives
that have been studied in computer vision, but their definition remains fuzzy
• There are many other primitives that can be more rigorously defined or at least conceptually easier to define
– Corner, line, circle, ellipse, square, triangle, …
• The ultimate vision tasks involve the detection of general objects
– Face, pedestrian, vehicle, mouth, eyes, door
![Page 105: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/105.jpg)
105
Two Paradigms
• Model-based approaches– Build an explicit model to characterize the objects we want
to detect
– Suitable for the class of simple objects for which good models are relatively easy to find
– Examples: corner/line/circle detection
• Data-driven (machine learning) approaches– Provide a training set (e.g., manually detected results) and
detector works like a black box
– Suitable for the class of complex objects for which good models are NOT easy to find
– Examples: neural network, support vector machine
![Page 106: Edge Detection - Asian Institute of Technologyesl.ait.ac.th/courses/AT74.06/class11 - edge detection.pdf · 2017-04-05 · face detection/recognition, ... objects components (such](https://reader034.fdocuments.in/reader034/viewer/2022042915/5f53819c42e3fa56bc764339/html5/thumbnails/106.jpg)
Questions?