ip-lecture4-2011
TRANSCRIPT
-
8/3/2019 IP-lecture4-2011
1/54
1/12/2012 Computer Graphics & ImageProcessing
1
Computer GraphicsComputer Graphics&&Image ProcessingImage Processing
Anuja Dharmaratne,Anuja Dharmaratne,PhDPhD
UCSCUCSC
-
8/3/2019 IP-lecture4-2011
2/54
1/12/2012 Computer Graphics & ImageProcessing
2
Lecture 4Lecture 4
Point Detection
Line Detection Edge Detection
Edge Thinning
Edge Linking
-
8/3/2019 IP-lecture4-2011
3/54
1/12/2012 Computer Graphics & ImageProcessing
3
Point DetectionPoint Detection
Smallest feature in an image.
The simplest point detection operatoris a high value surrounded by lowones.
-
8/3/2019 IP-lecture4-2011
4/54
1/12/2012 Computer Graphics & ImageProcessing
4
-
8/3/2019 IP-lecture4-2011
5/54
1/12/2012 Computer Graphics & ImageProcessing 5
Line Detection
Line Detection Filters
-1 -1 -1
2 2 2-1 -1 -1
-1 2 -1
-1 2 -1-1 2 -1
2 -1 -1
-1 2 -1-1 -1 2
-1 -1 2
-1 2 -12 -1 -1
The above line detector filters should be appliedto detect lines in an image with the relevantdirections.
-
8/3/2019 IP-lecture4-2011
6/54
1/12/2012 Computer Graphics & ImageProcessing 6
DetectingDetectingLinesLines
orientedoriented
inin --4545oo
directiondirection
-
8/3/2019 IP-lecture4-2011
7/54
1/12/2012 Computer Graphics & ImageProcessing 7
Detecting linesDetecting lines ininhorizontalhorizontal directiondirection
Gray scale image binary output image afterthresholding
-
8/3/2019 IP-lecture4-2011
8/54
1/12/2012 Computer Graphics & ImageProcessing 8
Edge/Boundary DetectionEdge/Boundary Detection
What is Edge/Boundary detection ?
- Image processing technique in whichedge pixels are identified by examiningtheir neighboring pixels.
-
8/3/2019 IP-lecture4-2011
9/54
1/12/2012 Computer Graphics & ImageProcessing 9
What is an Edge?
Edges of objects in a digital image arerepresented by the discontinuities ofthe intensity or the grey-level.
High grey-level value
Low grey-level value
Edge
If a pixel haswidelyvarying greylevels, thenit might bean edge.
-
8/3/2019 IP-lecture4-2011
10/54
1/12/2012 Computer Graphics & ImageProcessing 10
An edge is a set of connected pixels thatlies on a boundary between two regions
A fast rate of change of intensity at somedirection
What is an edge?What is an edge?
A ramp edgeAn ideal edge
Intensitylevel
-
8/3/2019 IP-lecture4-2011
11/54
1/12/2012 Computer Graphics & ImageProcessing 11
-
8/3/2019 IP-lecture4-2011
12/54
Real EdgesReal Edges
Noisy and Discrete!
We want an Edge Operator that produces:
Edge Magnitude
Edge Orientation
High Detection Rate and Good Localization
-
8/3/2019 IP-lecture4-2011
13/54
1/12/2012 Computer Graphics & ImageProcessing 13
The gradient direction is given by:
The edge strength is given by the gradient
magnitude
The gradient of an image: = [ Gx , Gy ]
Image GradientImage Gradient
-
8/3/2019 IP-lecture4-2011
14/54
1/12/2012 Computer Graphics & ImageProcessing 14
First Derivative Based Techniques
The overall gradient at (x,y ) is given by
G(x,y) = ((df/dx)2+(df/dy)
2)
This is approximated by
G(x,y) } |df/dx| + |df/dy|
If G(x,y) >T then (x,y) is in an edge point. WhereT is a threshold. (10% of the highest G(x,y) maybe a good estimate).
Derivative of the image function has twocomponents
f(x,y) = ( d f(x,y) , d f(x,y) )dx dy
-
8/3/2019 IP-lecture4-2011
15/54
1/12/2012 Computer Graphics & ImageProcessing 15
Edge DetectionEdge DetectionOperatorsOperators
All the operators used forimage sharpening can be usedfor edge detection, too.
Successive Difference Operator
Roberts Cross operator
Prewitt Operator Sobel Operator
-
8/3/2019 IP-lecture4-2011
16/54
1/12/2012 Computer Graphics & ImageProcessing 16
Successive DifferenceSuccessive DifferenceOperatorOperator
1 -1
0 0
1 0
-1 0
Gx Gy
Roberts Cross operatorRoberts Cross operator
1, jiI 1,1 jiI
jiI , jiI ,1I
-
8/3/2019 IP-lecture4-2011
17/54
1/12/2012 Computer Graphics & ImageProcessing 17
-1 -1 -1
0 0 0
1 1 1
-1 0 1
-1 0 1
-1 0 1
Prewitt operators
-1 -2 -1
0 0 0
1 2 1
-1 0 1
-2 0 2
-1 0 1
Sobel operators
0 1 2
-1 0 1
-2 -1 0
-2 -1 0
-1 0 1
0 1 2
Weighted value 2 is given to achieve some smoothingby giving more importance to center point
-
8/3/2019 IP-lecture4-2011
18/54
1/12/2012 Computer Graphics & ImageProcessing 18
Sobel OperatorSobel Operator
More sensitive to X and Y directional edges When compared with Successive DifferenceOperator, Roberts Cross Operator and PrewittOperator
Calculation is more complexLess sensitive to noise
-
8/3/2019 IP-lecture4-2011
19/54
1/12/2012 Computer Graphics & ImageProcessing 19
Other operatorsOther operators
Kirsh Compass Mask
Robinson Compass Mask
Laplacian Operator Frei-Chen Mask
-
8/3/2019 IP-lecture4-2011
20/54
1/12/2012 Computer Graphics & ImageProcessing 20
ResultsResults
Original image Sobel Operator
PrewittOperator Frei-ChenOperator RobertsOperator
LaplacianOperator
RobinsonOperator
Kirsh Operator
-
8/3/2019 IP-lecture4-2011
21/54
Comparing Edge OperatorsComparing Edge Operators
-1 0 1
-1 0 1
-1 0 1
1 1 1
0 0 0
-1 -1 1
Gradient:
Roberts (2 x 2):
Sobel (3 x 3):
Sobel (5 x 5): -1 -2 0 2 1
-2 -3 0 3 2
-3 -5 0 5 3
-2 -3 0 3 2
-1 -2 0 2 1
1 2 3 2 1
2 3 5 3 2
0 0 0 0 0
-2 -3 -5 -3 -2
-1 -2 -3 -2 -1
0 1
-1 0
1 0
0 -1
Good Localization
Noise SensitivePoor Detection
Poor LocalizationLess Noise SensitiveGood Detection
-
8/3/2019 IP-lecture4-2011
22/54
1/12/2012 Computer Graphics & ImageProcessing 22
22ndnd Derivative techniquesDerivative techniques
Sign of the second derivative is used tofind the edge pixels.
Zero crossing property of the secondderivative is used to find thick edges ofan image.
i.e. Line joining the extreme positive andnegative values of the second derivative
would cross zero near the midpoint of theedge.
-
8/3/2019 IP-lecture4-2011
23/54
1/12/2012 Computer Graphics & ImageProcessing 23
22ndnd derivative techniquesderivative techniques
Laplacian Operator
Lalpacian of Gaussian Marr-Hildreth Operator
-
8/3/2019 IP-lecture4-2011
24/54
1/12/2012 Computer Graphics & ImageProcessing 24
Laplacian FiltersLaplacian FiltersIdea:
Smooth the image,
compute the second derivative ofthe (2D) image,
Find the pixels where the brightnessfunction crosses 0 and mark them.
We can actually devise convolution
filters that carry out the smoothing andthe computation of the secondderivative.
-
8/3/2019 IP-lecture4-2011
25/54
1/12/2012Computer Graphics & ImageProcessing
25
Laplacian Operator
Digital Laplacian Discrete variants (applied after smoothing):
2 f(x,y) = d2 f(x,y) + d2 f(x,y)
dx2 dy2
0 1 0
1 -4 1
0 1 0
1 1 1
1 -8 1
1 1 1
2 -1 2
-1 -4 -1
2 -1 2
Continuous variant:
-
8/3/2019 IP-lecture4-2011
26/54
1/12/2012 Computer Graphics & ImageProcessing
26
Laplacian FiltersLaplacian Filters
3v3 Laplacian 5v5 Laplacian
zerodetection
zerodetection
zerodetection
7v7 Laplacian
-
8/3/2019 IP-lecture4-2011
27/54
1/12/2012 Computer Graphics & ImageProcessing
27
Finding Zero-crossings
(x-1, y-1) (x,y-1) (x+1,y-1)
(x-1, y) (x,y) (x+1,y)
(x-1, y+1) (x,y+1) (x+1,y+1)
If (G(x,y)=0 Then
I
f (G(x-1,y-1)* G(x+1,y+1))
-
8/3/2019 IP-lecture4-2011
28/54
1/12/2012 Computer Graphics & ImageProcessing
28
Sensitive to noise: This sensitivity comesnot just from the sensitivity of the zero-crossings, but also of the differentiation. Ingeneral, the higher the derivative, the more
sensitive the operator.
Need to reduce the sensitivity.Therefore, usually convolution is applied ona smoothed image. Thus, smooth the imagewith a Gaussian filter, first. Then, apply theLaplacian filter.
Properties ofLaplacianProperties ofLaplacianOperatorOperator
-
8/3/2019 IP-lecture4-2011
29/54
1/12/2012 Computer Graphics & ImageProcessing
29
Gaussian Distribution
The 2D Gaussian distribution function intwovariables, G(x,y), is illustrated and defined by,
Where isthe standard deviation.
-
8/3/2019 IP-lecture4-2011
30/54
1/12/2012 Computer Graphics & ImageProcessing
30
Simply, first Convolving the Laplacian tothe Gaussian and then applying theresulting filter for edge detection is called
Laplacian of Gaussian (LoG). Therefore the total operation of edge
detection after smoothing on the originalimage is
s(x,y) = (f(x,y)*G(x,y)) *
Since Convolution is Associatives(x,y) = f(x,y) * (G(x,y) * )
Laplacian of GaussianLaplacian of Gaussian
-
8/3/2019 IP-lecture4-2011
31/54
1/12/2012 Computer Graphics & ImageProcessing
31
It issimple to show thatthis operation can be
reduced to convolve the original image f(x,y) with a``Laplacian of a Gaussian''(LOG) operator
,
2nd Derivative ofthe 2D Gaussian
Laplacian of GaussianLaplacian of Gaussian
-
8/3/2019 IP-lecture4-2011
32/54
1/12/2012 Computer Graphics & ImageProcessing
32
Laplacian and GradientLaplacian and Gradient Zero-crossings of Laplacian operators only
tell you where the edge is, not how strongthe edge is.
To get the strength of the edge, we canlook at the gradient magnitude at theposition of the Laplacian zero crossings.
-
8/3/2019 IP-lecture4-2011
33/54
1/12/2012 Computer Graphics & ImageProcessing
33
MarrMarrHildreth OperatorHildreth Operator This is a
derivation ofLOG.
First, filter
the imagewith aGaussianfilter
Then findzerocrossings
Variance
-
8/3/2019 IP-lecture4-2011
34/54
1/12/2012 Computer Graphics & ImageProcessing
34
MarrMarrHildreth OperatorHildreth Operator
sigma = 2original
sigma = 0.9sigma = 4
-
8/3/2019 IP-lecture4-2011
35/54
1/12/2012 Computer Graphics & ImageProcessing
35
DisadvantagesDisadvantages
Marr-Hildreth operator is symmetric, so itfinds edges in all orientations.
However, it generates responses that do
not correspond to edges, so-called "falseedges", and the localization error may besevere at curved edges.
Since it uses a second derivative operator,the influence of noise is considerable.
It produces unrealistic closed contours.
-
8/3/2019 IP-lecture4-2011
36/54
1/12/2012 Computer Graphics & ImageProcessing
36
Canny OperatorCanny Operator
Properties
Low error rate
Edge points be well localized
Have only one response to a single edge
This is the First derivative of the GaussianFunction
-
8/3/2019 IP-lecture4-2011
37/54
1/12/2012 Computer Graphics & ImageProcessing
37
Canny AlgorithmCanny Algorithm
1. Smooth the image
2. Find the image gradient in both X and Y directions
3. Apply Non-maximum suppression
4. Reduce gradient array by hysteresis Using two
thresholds
-
8/3/2019 IP-lecture4-2011
38/54
1/12/2012 Computer Graphics & ImageProcessing
38
Canny Algorithm (contd.)Canny Algorithm (contd.)1. Filter outnoise using Gaussian filter
2. Find the edge strength bytaking the gradient
ofthe image uses Sobel operator
Uses a pair of3x3 convolution masks
-
8/3/2019 IP-lecture4-2011
39/54
1/12/2012 Computer Graphics & ImageProcessing
39
Canny Algorithm (contd.)Canny Algorithm (contd.)After calculating Gx=P[i,j] and Gy=Q[i,j],
compute the magnitude and orientationof the gradient vector at position [i, j]:
22
],[],[],[ jiQjiPjiM !]),[],,[arctan(],[ jiPjiQji !U
This is exactly the information that wewant it tells us where edges are, howsignificant they are, and what theirorientation is.
-
8/3/2019 IP-lecture4-2011
40/54
1/12/2012 Computer Graphics & ImageProcessing
40
Canny Algorithm (contd.)Canny Algorithm (contd.)
After finding the direction ofthe gradient vector
U = tan-1(Gy / Gx),
relate the calculated directionto a directionthat can betraced in an image
-
8/3/2019 IP-lecture4-2011
41/54
1/12/2012 Computer Graphics & ImageProcessing
41
Canny Algorithm (contd.)Canny Algorithm (contd.)We first assign a sector ^[i, j] to each pixel according
to its associated edge orientation U[i, j]. There are foursectors with numbers 0, , 3:
180r 0r
135r
90r
45r
315r
270r
225r
0
0
0
0
11
1
1
2 2
2 2
33
3
3
-
8/3/2019 IP-lecture4-2011
42/54
1/12/2012 Computer Graphics & ImageProcessing
42
Canny Algorithm (contd.)Canny Algorithm (contd.) Then we iterate through the array M[i, j]
and compare each element to two of its8-neighbors.
Which two neighbors we choose dependson the value of^[i, j].
In the following diagram, the numbers inthe neighboring squares of [i, j] indicatethe value of^[i, j] for which theseneighbors are chosen:
3 2 1
0 [i,j] 0
1 2 3
-
8/3/2019 IP-lecture4-2011
43/54
1/12/2012 Computer Graphics & ImageProcessing
43
Canny Algorithm (contd.)Canny Algorithm (contd.)3. Applynon maximum suppression
-
8/3/2019 IP-lecture4-2011
44/54
1/12/2012 Computer Graphics & ImageProcessing
44
Predicting the next edge point
Assume the marked point is an
edge point. Then we constructthe tangent to the edge curve
(which is normal to the gradient at
that point) and use this to predict
the next points (here either r or s).
At q, we have a
maximum ifthe value islargerthanthose at both
p and at r.
Canny Algorithm (contd.)Canny Algorithm (contd.)
-
8/3/2019 IP-lecture4-2011
45/54
1/12/2012 Computer Graphics & ImageProcessing
45
4. Eliminating streaking by using hysteresis
- Usestwo thresholds high and low
Canny Algorithm (contd.)Canny Algorithm (contd.)
If the magnitude is below the fir st threshold (T1), it
is set to zero (made a non-edge). If the magnitude
is above the high threshold (T2), it is made an edge.
And if the magnitude is between the 2 thresholds,
then it is set to zero unless there is a path from this
pixel to a p ixel with a gradient above T2.
-
8/3/2019 IP-lecture4-2011
46/54
1/12/2012 Computer Graphics & ImageProcessing
46
Canny Algorithm (contd.)Canny Algorithm (contd.)
First derivative based techniques alwaysproduce more than one pixel as edge pointsin a boundary.
Selecting the highest gradient pixel andelimination (suppression) of other non-maximums is performed by Non-MaximumSuppression operation.
Thus, this non-maxima suppression techniquethins the detected edges to a width of onepixel.
dd
-
8/3/2019 IP-lecture4-2011
47/54
1/12/2012 Computer Graphics & Image
Processing
47
Canny Edge DetectorCanny Edge Detector --ExampleExample
Let us look at the following sample imageand perform Canny edge detection on it:
grayscale image
385456978579
69618490105100
82100101121165176
7187119182202211
101131180200215209
78120170183213220
intensity values of
same image
C EdC Ed
-
8/3/2019 IP-lecture4-2011
48/54
1/12/2012 Computer Graphics & Image
Processing
48
Canny Edge DetectorCanny Edge Detector --ExampleExample
Applying the horizontal and vertical gradient filtersgives us the following results:
P[i,j]
000000
0-4-12.5-23.5-1.55.5
0-5-12-13-29.5-3
0-17-16.5-41.5-32-10
0-23-40.5-41.5-17.5-1.5
0-36-49.5-16.5-22.5-0.5
Q[i,j]
000000
01917.510.56.520.5
026282445.568
0-122.539.54936
03752.539.515.5-5.5
0-17-10.5-13.5-9.54.5
-
8/3/2019 IP-lecture4-2011
49/54
1/12/2012 Computer Graphics & Image
Processing
49
Canny Edge DetectorCanny Edge Detector -- ExampleExample
Based on P[i, j] and Q[i, j], we can now compute themagnitude and orientation of the gradient:
M[i, j]
000000
019.421.525.76.721.2
026.530.527.354.268.1
020.816.757.358.537.4
043.666.357.323.45.7
039.850.621.324.44.5
U[i, j]
180r180r180r180r180r180r
180r281r305r335r282r254r
180r280r293r298r302r272r
180r35r351r316r303r285r
180r301r307r316r318r285r
180r25r11r39r22r276r
-
8/3/2019 IP-lecture4-2011
50/54
1/12/2012 Computer Graphics & Image
Processing
50
Canny Edge DetectorCanny Edge Detector -- ExampleExample
This allows us to compute the sector ^[i, j]for each angle U[i, j]:
^[i, j]
000000
023322
023332
010332
033332
010112 Remember thedirections:
321
0[i,j]0
123
-
8/3/2019 IP-lecture4-2011
51/54
1/12/2012 Computer Graphics & Image
Processing
51
Canny Edge DetectorCanny Edge Detector -- ExampleExample
The last steps are nonmaxima suppression andthresholding
(here we use a single threshold T = 30):
E[i, j]
000000
000000
026.50054.268.1
00057.358.50
0066.357.300
0050.6024.40
final result
000000
000000
000011
000110
001100
001000
-
8/3/2019 IP-lecture4-2011
52/54
1/12/2012 Computer Graphics & Image
Processing
52
Canny Edge DetectorCanny Edge Detector -- ExampleExampleFinally we visualize the detected edge pixels (0 =white, 1 = black) and indicate the precise edgelocations (the pixels lower right corners) in theoriginal image:
edge locations inoriginal image
edge pixels
-
8/3/2019 IP-lecture4-2011
53/54
1/12/2012 Computer Graphics & Image
Processing
53
Important ParametersImportant Parameters
Width ofthe Gaussian kernel
Upperthreshold
Lowerthreshold
Weak point of Canny OperatorWeak point of Canny Operator
Doesnt trace Y junctions properly
-
8/3/2019 IP-lecture4-2011
54/54
1/12/2012 Computer Graphics & Image
Processing
54
ExampleExample
W!8!8! W!8!8!
W 8 8 W 8 8