<a id="easyimage-canny-edge-detector"></a>

# Canny Edge Detector

The Canny edge detector facilitates:

* Good detection: finds all edges.
* Good localization: the found edges are as close as possible to the “real” edges in the image.
* Minimal response: one edge response is accepted for each position, i.e. avoiding multiple close or intersecting edge responses.

![](assets/images/easyimage/cannyedgedetectorsource.webp)![](assets/images/easyimage/cannyedgedetectorresult.webp)

The **EasyImage** Canny edge detector produces a binary output image where pixels corresponding to edges are set to 255 and all others are set to 0.

The Canny edge detector can be configured with three parameters:

* **Scale of the features of interest**: the standard deviation of the Gaussian filter used to smooth the source image, called the smoothing scale.
* **Gradient threshold with hysteresis**: maximum magnitude of the gradient of the source image expressed as a fraction ranging from 0 to 1 (two values).
* **Threshold mode**: which defines whether the threshold values should be interpreted as absolute or relative.

The API of the Canny edge detector is a single class, [`ECannyEdgeDetector`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html), with the following methods:

* [`ECannyEdgeDetector::Apply`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#a7ea4559d8fe21fec3c7b9742d0d22835) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#a26d881378dcd2c60483779230c7b5a88) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#a7e2427903cc64582b1f290e732877a3e): applies the Canny edge detector on an image/ROI.
* [`ECannyEdgeDetector::GetHighThreshold`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#a40edd05a95b7a65dcd83fba2cf13ec84) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#a697b12e7bd3a919c4c99822871cddd62) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#ae0c0e61e7f79d00d9d50c0ae6ef43f4c): returns the high hysteresis threshold to consider that a pixel is an edge.
* [`ECannyEdgeDetector::GetLowThreshold`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#af955ed1352d9593ced4db8d6d242218e) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#af1c291efe245ef756e1b631f6bcea297) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#a927be2bb644ecb0edfa8c0d7bf0bfac1): returns the low hysteresis threshold to consider that a pixel is an edge.
* [`ECannyEdgeDetector::GetSmoothingScale`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#a9574f80ca0f889e26a4870b2cf2ae2f8) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#a82256a526ad7d27c83920bbf9ea098c6) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#a3ac1552ca345df38d97b8d05649184b3): returns the scale of the features of interest.
* [`ECannyEdgeDetector::GetThresholdingMode`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#ae3f79c75d0df3065c424ac028ea9274c) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#a2f242034c74e806ce5e2e824643dff72) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#aa27ea7447ced6b3a25f647c62d6996df): returns the mode of the hysteresis thresholding.
* [`ECannyEdgeDetector::ResetSmoothingScale`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#a0fa02fb89c910d871004b786998b2add) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#a219aef551e94fe84e8ab696af797621a) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#a20e04b33c1b70e805022f4044a2c8896): prevents the smoothing of the source image by a Gaussian filter.
* [`ECannyEdgeDetector::SetHighThreshold`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#aff6280cfabd229db5a808073d01e231c) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#a697b12e7bd3a919c4c99822871cddd62) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#ae0c0e61e7f79d00d9d50c0ae6ef43f4c): sets the high hysteresis threshold to consider that a pixel is an edge.
* [`ECannyEdgeDetector::SetLowThreshold`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#a57f9a4f0c4115185a4e5c0f2908a62b7) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#af1c291efe245ef756e1b631f6bcea297) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#a927be2bb644ecb0edfa8c0d7bf0bfac1): sets the low hysteresis threshold to consider that a pixel is an edge.
* [`ECannyEdgeDetector::SetSmoothingScale`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#a46a4c42d01ed3c84c8f851eb4dace665) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#a82256a526ad7d27c83920bbf9ea098c6) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#a3ac1552ca345df38d97b8d05649184b3): sets the scale of the features of interest.
* [`ECannyEdgeDetector::SetThresholdingMode`](../../../doxygen_cpp/classeVision_1_1ECannyEdgeDetector.html#a1d00424932ec1959a2271a18bc311c5b) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECannyEdgeDetector.html#a2f242034c74e806ce5e2e824643dff72) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECannyEdgeDetector.html#aa27ea7447ced6b3a25f647c62d6996df): sets the mode of the hysteresis thresholding.

The **result image** must have the same dimensions as the input image. Its dimension must be set using [`SetSize`](../../../doxygen_cpp/classeVision_1_1EBaseROI.html#a8446337051c589320cfd2ea1fcbe6d16) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EBaseROI.html#a87cfe59bbf851719b3f65d6766f71dba) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EBaseROI.html#a43f0fddfd46389cc8b95d9ccb608a909)

<a id="easyimage-canny-edge-detector-quick-links"></a>

## See Also

Easy to understand, ready to copy code snippets.

Detect corners in an image.

Using morphological operators to detect edges.

Compute gradient magnitude and direction maps from a grayscale image.
