IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

Detects edges in a 2d image using Canny's algorithm. More...

IPSDKIPLFEATUREDETECTION_API image::ImagePtr ipsdk::imaproc::fd::cannyEdges2dImg (const image::ImageConstPtr &pInGxImg, const image::ImageConstPtr &pInGyImg, const ipsdk::imaproc::attr::CannyThresholdsConstPtr &pThresholds)
 wrapper function for detection of edges in images using Canny's algorithm More...
 
IPSDKIPLFEATUREDETECTION_API void ipsdk::imaproc::fd::cannyEdges2dImg (const image::ImageConstPtr &pInGxImg, const image::ImageConstPtr &pInGyImg, const ipsdk::imaproc::attr::CannyThresholdsConstPtr &pThresholds, const ipsdk::imaproc::attr::eProcessingOptimizationPolicy &inOptOptimizationPolicy, const image::ImagePtr &pOutImg)
 wrapper function for detection of edges in images using Canny's algorithm More...
 

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

Attributes description

Attribute description for algorithm :

Name ToolTip Default Initializer
ipsdk::imaproc::attr::InGxGreyImg2d [Input] 2d grey levels image of gradient computed along x-axis X
ipsdk::imaproc::attr::InGyGreyImg2d [Input] 2d grey levels image of gradient computed along y-axis X
ipsdk::imaproc::attr::InCannyThresholds [Input] low and high thresholds used for the Canny edges detection during the hysteresis phasis X
ipsdk::imaproc::attr::InOptOptimizationPolicy [Input Optional] processing optimization policy for algorithm X
ipsdk::imaproc::attr::OutOptWk1BinImg [Output Optional] Temporary working image for algorithm X
ipsdk::imaproc::attr::OutOptWk2BinImg [Output Optional] Temporary working image for algorithm X
ipsdk::imaproc::attr::OutOptWk1LabelImg [Output Optional] Temporary working image for algorithm X
ipsdk::imaproc::attr::OutBinImg [Output] binary image for processing operation ipsdk::imaproc::duplicateInOut (_pOutBinImg, _pInGxGreyImg2d, ipsdk::image::eImageBufferType::eIBT_Binary)

Global Rule description

Global rule description for algorithm :
ipsdk::imaproc::matchSizeAndType (_pInGxGreyImg2d,_pInGyGreyImg2d) && 
ipsdk::imaproc::matchSize (_pInGxGreyImg2d,_pOutBinImg) && 
(ipsdk::processor::ifIsSet (
  _pOutOptWk1BinImg, (
   ipsdk::imaproc::matchSize (_pInGxGreyImg2d,_pOutOptWk1BinImg)))) && 
(ipsdk::processor::ifIsSet (
  _pOutOptWk2BinImg, (
   ipsdk::imaproc::matchSize (_pInGxGreyImg2d,_pOutOptWk2BinImg)))) && 
(ipsdk::processor::ifIsSet (
  _pOutOptWk1LabelImg, (
   ipsdk::imaproc::matchSize (_pInGxGreyImg2d,_pOutOptWk1LabelImg))))

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

Associated library

IPSDKIPLFeatureDetection

Header file

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);
See also
CannyEdges2dImgLvl1
CannyEdges2dImgLvl2
CannyEdges2dImgLvl3

Function Documentation

◆ cannyEdges2dImg() [1/2]

IPSDKIPLFEATUREDETECTION_API image::ImagePtr ipsdk::imaproc::fd::cannyEdges2dImg ( const image::ImageConstPtr pInGxImg,
const image::ImageConstPtr pInGyImg,
const ipsdk::imaproc::attr::CannyThresholdsConstPtr pThresholds 
)

wrapper function for detection of edges in images using Canny's algorithm

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ cannyEdges2dImg() [2/2]

IPSDKIPLFEATUREDETECTION_API void ipsdk::imaproc::fd::cannyEdges2dImg ( const image::ImageConstPtr pInGxImg,
const image::ImageConstPtr pInGyImg,
const ipsdk::imaproc::attr::CannyThresholdsConstPtr pThresholds,
const ipsdk::imaproc::attr::eProcessingOptimizationPolicy inOptOptimizationPolicy,
const image::ImagePtr pOutImg 
)

wrapper function for detection of edges in images using Canny's algorithm

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure