canny’s algorithm for edge detection
DESCRIPTION
Canny’s Algorithm for Edge Detection. David Bisaccia. Objectives. History and Application Gray Scale vs. Color Convolution Mask Gradient Image Peaks Double Threshold and Final Peaks Output. History. Developed by John Canny in 1986. Application. Used to find edges in images - PowerPoint PPT PresentationTRANSCRIPT
David Bisaccia
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
HistoryDeveloped by John Canny in 1986
ApplicationUsed to find edges in imagesCan be used for defense, security, and much
moreFace Detection or Human Detection
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
Gray Scale vs. ColorColor typically isn’t need when looking for
edgesLess Computation in gray scale, no R,B,G,A
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
Loud Noises!Images can have noise in them
Heat wavesDustSmokeAcquisition Noise
Solution: Convolution MaskSuppresses NoiseAverages a pixel with surrounding pixelsSimple mask below
Scan the convolution mask below across the target image (dot product)
Ignore the edges, usually don’t matter
1/4 1/4
1/4 1/4
Dot Product Applied23
45
12
67
90
12
23
44
66
67
36
28
45
65
87
56
78
90
73
1
3 45
6 7 88
1/4 1/4
1/4 1/4* = 35
Before Convolution:
23
45
12
67
90
12
35
44
66
67
36
28
45
65
87
56
78
90
73
1
3 45
6 7 88
After Convolution: Table
Current Pixel
Overlapped pixel’s with Mask (needed for dot product)
Gaussian MaskUses Gaussian Mask Sigma is a value chosen by youX and Y are the distances away
from target pixelRange from positive to negative
Mask RadiusMask Radius = 3 * Sigma
22 2/ xe
Gaussian Mask: Pseudo Codeint Maskx[][], Masky[][];Sigma = 3;int MaskRadius = Sigma * 3;
For P = -MaskRadius to +MaskRadiusFor Q = -MaskRadius to +MaskRadius
Maskx[P+MaskRadius][Q+MaskRadius] =-Q*e^(-(P*P + Q*Q)/(2*Sigma));
Masky[P+MaskRadius][Q+MaskRadius] =-P*e^(-(P*P + Q*Q)/(2*Sigma));
222 2/)( yxex
Applying the Gaussian MaskNeed to convolve the target picture with the
Gaussian MaskNeed to do it for the X and Y directionsYields a output convolved X and output
convolved Y matrix (outConvX, outConvY)
Applying the Mask: Pseudo CodeFor i = MaskRadius to Picture Max Row –
MaskRadius For j =MaskRadius to Picture Max Column
MaskRadius -Convolve the current pixel, Pic[i][j], with the maskX -Save result in outConvX[][] -Convolve the current pixel, Pic[i][j], with the maskY -Save result in outConvY[][]
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
Gradient ImageAchieved by obtaining the magnitude for
each pixel from the outConvX[][] and the outConvY[][]
Saved in a matrix named Magnitude[][]Iterate through each pixel i and j
Magnitude[i][j] =)][j]outConvY[i ][j]outConvX[i 22
Getting the SlopeSlope = Δy/ ΔxSlope =The slope for each pixel will determine what
neighboring pixels will be compared with the current pixel
vX[][])][]/outCon(outConvY[tan -1
Getting the Slope (cont.)If slope -22.5 to 22.5
If slope 22.5 to 67.5
If slope -67.5 to -22.5
Else
TableRelevant Neighbor Pixel
Current Pixel
Example SlopeThe slope for each pixel will determine what
neighboring pixels will be compared with the current pixel
Compare the Red Neighbors with Current Pixel Value(Green)A slope of 10 degrees
A slope of 85 degrees
TableRelevant Neighbor Pixel
Current Pixel
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
PeaksPeaks is represented as a boolean matrix for
each pixel of the image, peak[][]If it is true, then that pixel is considered a
possible peakIf false, then that pixel is not a peak
Getting PeaksFor each pixel use the relevant neighbor pixel
magnitudes and compare with the current pixel’s magnitude
If current pixel’s Magnitude[i][j] > relevant pixel’s Magnitude[i][j]
Then peak[i][j] = trueElse peak[i][j] = false
Example of PeaksThe matrix is represented with values
of the pictures Magnitude[][]Since current pixel’s Magnitude[i][j] > relevant
pixel’s Magnitude[i][j]peak[i][j] = true
Since current pixel’s Magnitude[i][j] < relevant pixel’s Magnitude[i][j]
peak[i][j] = false
12
34
23
85
90
30
23
78
90
12
34
23
85
90
99
23
78
90
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
Double ThresholdFinal[] is another boolean matrix that represents
peak values that are accepted by the double threshold
High ThresholdValues is selected by the programmerIf the Magnitude[] > High Threshold and peak[] ==
true then that pixel is a peak in Final[] Low Threshold
Value is selected by the programmerIf the Magnitude[] > Low Threshold and peak[] ==
trueand that pixel has a neighboring pixel that is connected to a pixel with a high threshold
Getting the High ThresholdFor i = 0 to Row length
For j = 0 to column lengthif(peak[i][j] == true && magnitude[i][j] >
High)peak[i][j] = falsefinal[i][j] = true
else if(peak[i][j] == false && magnitude[i][j] < Lo)
peak[i][j] == falsefinal[i][j] == false
Example High Threshold
7 77
43
32
21
21
45
81
1 91
1 1
34
43
65
67
34
2
1 1 91
1 1 1
91
1 1 1 92
1
1 83
82
82
3 2
Magnitude Table Peak Table Final Table
TableTrue Peak True Final
False Peak False Final
Threshold: 80
Getting The Low ThresholdMoreToDo = OnWhile(MoreToDo == On)
For i = 0 to Row lengthFor j = 0 to column length
if(Final[i][j] == true) For p = -1 to 1
For q = -1 to 1 if(peak[i+p][j+q] == true) Final[i+p][j+q] == true
peak[i+p][j+q] = falseMoreToDo = On
Example Low ThresholdGeneral Peaks Table with High and Low:
Final Table:
TableLow Peak
High Peak True Final
False Peak False Final
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
OutputFor i = 0 to Row length
For j = 0 to column lengthif(Final[i][j] == true)
print white pixelelse
print black pixel
Example Inputs and OutputsInput Magnitude Peaks
Output:
Home WorkIs this a peak?
12
34
23
85
90
30
23
78
90
SourcesMachine Vision : Theory, Algorithms,
Practicalities. E.R. DaviesWikipedia for pictures