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
![Page 1: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/1.jpg)
David Bisaccia
![Page 2: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/2.jpg)
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
![Page 3: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/3.jpg)
HistoryDeveloped by John Canny in 1986
![Page 4: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/4.jpg)
ApplicationUsed to find edges in imagesCan be used for defense, security, and much
moreFace Detection or Human Detection
![Page 5: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/5.jpg)
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
![Page 6: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/6.jpg)
Gray Scale vs. ColorColor typically isn’t need when looking for
edgesLess Computation in gray scale, no R,B,G,A
![Page 7: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/7.jpg)
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
![Page 8: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/8.jpg)
Loud Noises!Images can have noise in them
Heat wavesDustSmokeAcquisition Noise
![Page 9: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/9.jpg)
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
![Page 10: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/10.jpg)
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)
![Page 11: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/11.jpg)
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
![Page 12: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/12.jpg)
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
![Page 13: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/13.jpg)
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)
![Page 14: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/14.jpg)
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[][]
![Page 15: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/15.jpg)
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
![Page 16: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/16.jpg)
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
![Page 17: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/17.jpg)
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
![Page 18: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/18.jpg)
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
![Page 19: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/19.jpg)
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
![Page 20: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/20.jpg)
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
![Page 21: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/21.jpg)
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
![Page 22: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/22.jpg)
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
![Page 23: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/23.jpg)
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
![Page 24: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/24.jpg)
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
![Page 25: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/25.jpg)
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
![Page 26: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/26.jpg)
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
![Page 27: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/27.jpg)
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
![Page 28: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/28.jpg)
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
![Page 29: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/29.jpg)
Example Low ThresholdGeneral Peaks Table with High and Low:
Final Table:
TableLow Peak
High Peak True Final
False Peak False Final
![Page 30: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/30.jpg)
ObjectivesHistory and ApplicationGray Scale vs. ColorConvolution MaskGradient ImagePeaksDouble Threshold and Final PeaksOutput
![Page 31: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/31.jpg)
OutputFor i = 0 to Row length
For j = 0 to column lengthif(Final[i][j] == true)
print white pixelelse
print black pixel
![Page 32: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/32.jpg)
Example Inputs and OutputsInput Magnitude Peaks
Output:
![Page 33: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/33.jpg)
Home WorkIs this a peak?
12
34
23
85
90
30
23
78
90
![Page 34: Canny’s Algorithm for Edge Detection](https://reader030.vdocuments.net/reader030/viewer/2022012406/5681332a550346895d9a1b87/html5/thumbnails/34.jpg)
SourcesMachine Vision : Theory, Algorithms,
Practicalities. E.R. DaviesWikipedia for pictures