IPSDK 4.1.0.2
IPSDK : Image Processing Software Development Kit
2d Canny edge detector
imagecannyEdges2dImg (inGxImg,inGyImg,thresholds)

Detailed Description

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:

  1. from Gx and Gy images, magnitude and orientation of gradient is computed
  2. 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.
  3. 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
  4. 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 ( $InCannyThresholds=(64, 128)$, gradient images were computed applying a Sobel operator, with a half-kernel size=1, without normalization) :

cannyEdges2d.png
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

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# associated gradient images computation
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

ImageConstPtr pInImg = loadTiffImageFile(inImgPath);
ImageGeometryPtr pGradGeometry = geometry2d(eImageBufferType::eIBT_Real32, pInImg->getSizeX(), pInImg->getSizeY());
boost::shared_ptr<MemoryImage> pGxImg = boost::make_shared<MemoryImage>();
pGxImg->init(*pGradGeometry);
boost::shared_ptr<MemoryImage> pGyImg = boost::make_shared<MemoryImage>();
pGyImg->init(*pGradGeometry);
ImageGeometryPtr pOutGeometry = geometry2d(eImageBufferType::eIBT_Binary, pInImg->getSizeX(), pInImg->getSizeY());
boost::shared_ptr<MemoryImage> pOutImg = boost::make_shared<MemoryImage>();
pOutImg->init(*pOutGeometry);
filter::sobelGradient2dImg(pInImg, eSobelKernelType::eSKT_SobelHalfKnlSz1, false, pGxImg, pGyImg);
cannyEdges2dImg(pGxImg, pGyImg, pThresholds, eProcessingOptimizationPolicy::ePOP_MaximizeSpeed, pOutImg);