image = | cannyEdges2dImg (inGxImg,inGyImg,thresholds) |
Detects edges in a 2d image using Canny's algorithm.
Detects edges in a 2d image using Canny's algorithm, and generates an output binary image, with pixels associated to the found contours in white, and the rest in black.
Given 2 gradient images (computed, for instance, thanks to Sobel Gradient 2d or Gaussian Gradient 2d), respectively along x (Gx image) and y-axis (Gy image), Canny edge detector can be decomposed into the following steps:
- from Gx and Gy images, magnitude and orientation of gradient is computed
- non-maxima suppression: for each pixel in the image of gradient magnitude, if the pixel value is greater than the values of its 2 neighbours along the gradient direction, then the pixel is marked as "to be processed"; otherwise, it is marked as "not a contour". This step prevents from having contours with a thickness greater than 1 pixel.
- for all pixels tagged "to be processed", mark as:
- "not a contour" pixels whose gradient magnitude value is lower than low threshold value specified by the user
- "strong contour" pixels whose gradient magnitude value is higher than high threshold value specified by the user
- "perhaps a contour" pixels whose gradient magnitude value is between low and high threshold values
- process pixels tagged "perhaps a contour": a pixel tagged "perhaps a contour" is a strong contour if it is directly or indirectly (ie. there exists a path of connected pixels tagged "perhaps a contour" that link the current pixel to a "strong
contour" pixel) connected to a "strong contour" pixel. Otherwise it is affected the "not a contour" value.
Here is an example of a Canny edge detector applied to the gradient images of an 8-bits grey levels input image (
, gradient images were computed applying a Sobel operator, with a half-kernel size=1, without normalization) :
- See also
- https://en.wikipedia.org/wiki/Canny_edge_detector
Example of Python code :
Example imports
import PyIPSDK
import PyIPSDK.IPSDKIPLFeatureDetection as fd
import PyIPSDK.IPSDKIPLFiltering as filter
Code Example
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
gxImg, gyImg = filter.sobelGradient2dImg(inImg)
outImg = fd.cannyEdges2dImg(gxImg, gyImg, PyIPSDK.createCannyThresholds(64, 128))
Example of C++ code :
Example informations
Header file
#include <IPSDKIPL/IPSDKIPLFeatureDetection/Processor/CannyEdges2dImg/CannyEdges2dImg.h>
Code Example
boost::shared_ptr<MemoryImage> pGxImg = boost::make_shared<MemoryImage>();
pGxImg->init(*pGradGeometry);
boost::shared_ptr<MemoryImage> pGyImg = boost::make_shared<MemoryImage>();
pGyImg->init(*pGradGeometry);
boost::shared_ptr<MemoryImage> pOutImg = boost::make_shared<MemoryImage>();
pOutImg->init(*pOutGeometry);