Canny Edge Detector
Model was written in NetLogo 5.0.4
•
Viewed 692 times
•
Downloaded 49 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This demonstrates each step of the Canny edge detector algorithm (except for the final, edge tracing step).
HOW IT WORKS
http://en.wikipedia.org/wiki/Cannyedgedetector#StagesoftheCannyalgorithm
HOW TO USE IT
First, hit "start-webcam" to initialize your camera. You can use use "display-mirror-to-patches" to test it.
Hit "go" to see it in action! Play with the settings!
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
extensions [gst-video bitmap] globals [cam-is-inited? xconv yconv max-grad] patches-own [bw new-bw grad gx gy] to start-webcam if (not (cam-is-inited? = true)) [ gst-video:camera-init set cam-is-inited? true ] gst-video:camera-start end to stop-webcam gst-video:camera-stop end to display-mirror-to-patches cam-mirror-to-patches display end to cam-mirror-to-patches if (gst-video:camera-is-rolling?) [ bitmap:copy-to-pcolors gst-video:camera-image false ] end to go no-display cam-mirror-to-patches ask patches [set bw brightness set new-bw bw] if horizontal-blur [ask patches [apply-horiz-gaussian]] if vertical-blur [ask patches [apply-vert-gaussian]] ask patches [set bw new-bw] ifelse detection-method != "None" [ ask patches [gradient] set max-grad max [grad] of patches ;ask patches [set pcolor scale-color white grad 0 max-grad] ask patches [color-patch] ] [ ask patches [set pcolor scale-color white bw 0 255] ] display end to-report brightness report mean pcolor end to color-patch ifelse grad <= high-thresh or (non-max-suppress and not max-edge?) [set pcolor black] [ ifelse color-gradient [set pcolor hsb (255 * atan gx gy / 360) 128 (255 * grad / max-grad)] [set pcolor scale-color white grad 0 max-grad] ] end to apply-horiz-gaussian let p1 [bw] of patch-at -2 0 let p2 [bw] of patch-at -1 0 let p4 [bw] of patch-at 1 0 let p5 [bw] of patch-at 2 0 set new-bw (2 * p1 + 4 * p2 + 5 * bw + 4 * p2 + 2 * p1) / 13 end to apply-vert-gaussian let p1 [bw] of patch-at 0 -2 let p2 [bw] of patch-at 0 -1 let p4 [bw] of patch-at 0 1 let p5 [bw] of patch-at 0 2 set new-bw (2 * p1 + 4 * p2 + 5 * bw + 4 * p2 + 2 * p1) / 13 end to-report max-edge? if grad < high-thresh [report false] let angle 45 * round ((atan gy gx) / 45) let x sin angle let y cos angle report grad >= [grad] of patch-at x y and grad >= [grad] of patch-at (- x) (- y) end to gradient let p1 [bw] of patch-at -1 1 let p2 [bw] of patch-at 0 1 let p3 [bw] of patch-at 1 1 let p4 [bw] of patch-at -1 0 let p6 [bw] of patch-at 1 0 let p7 [bw] of patch-at -1 -1 let p8 [bw] of patch-at 0 -1 let p9 [bw] of patch-at 1 -1 if detection-method = "Scharr" [ ; Scharr set gx (3 * p1 + 10 * p2 + 3 * p3) - (3 * p7 + 10 * p8 + 3 * p9) set gy (3 * p3 + 10 * p6 + 3 * p9) - (3 * p1 + 10 * p4 + 3 * p7) ] if detection-method = "Sobel" [ ; Sobel set gx (p1 + 2 * p2 + p3) - (p7 + 2 * p8 + p9) set gy (p3 + 2 * p6 + p9) - (p1 + 2 * p4 + p7) ] if detection-method = "Prewitt" [ set gx (p1 + p2 + p3) - (p7 + p8 + p9) set gy (p3 + p6 + p9) - (p1 + p4 + p7) ] set grad abs(gx) + abs(gy) ;report abs(gx) + abs(gy) end
There are 2 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
BryanHead_ProgressReport_May9th.docx | word | First progress report! | over 11 years ago, by Bryan Head | Download |
Canny Edge Detector.png | preview | Preview for 'Canny Edge Detector' | over 11 years ago, by Bryan Head | Download |