IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Hough circles detectionSee full documentation
HoughCircles2dPptieshoughCircles2d (inImg,radiusRange)
HoughCircles2dPptieshoughCircles2d (inImg,radiusRange,eCircleIntensityType,nbMaxPtsPerCircle,accumIntensityThreshold,removeTooCloseCirclesParams)
HoughCircles2dPptieshoughCircles2d (inGxImg,inGyImg,radiusRange)
HoughCircles2dPptieshoughCircles2d (inGxImg,inGyImg,radiusRange,method,eCircleIntensityType,maxAngleWithGradDir,nbMaxPtsPerCircle,accumIntensityThreshold,removeTooCloseCirclesParams,outImg1,outImg2)

Detailed Description

detects circles in image using Hough algorithm

This algorithm uses a variant of the Standard Circle Hough Transform to detect circles in a 2d grey levels image (or in a sequence of 2d grey levels images). Below is shown an example of application of Hough circles detector on an image of coins (circles detected by the algorithm are drawn in red on the right image; used range of radii equals to [10, 20]; all other input parameters are left to their default values):

houghCircles2d.png

1- Background: the Standard Circle Hough Transform

Standard Circle Hough Transform was inspired from Standard Line Hough Transform ([1]). Considering the user wants to detect circles with radii between minRadius and maxRadius, it works as follows:

a- pre-process the image by applying an edge extraction (Canny edge extraction, for instance)

b- create a 3D parameter space (also called accumulator matrix, or Hough space, or voting space). The 2 first dimensions correspond to the positions of the centers of the circles, and the 3rd dimension corresponds to the radii of the circles. Initialize the content of this 3D image with zeros.

c- for each pixel $(x_e, y_e)$ of the edge(s) detected in the input image in a), and for each radius $r$ in $[minRadius;maxRadius]$, increment pixels of coordinates $(x, y, r)$ in the 3D parameter space that satisfy the equation $(x-x_e)^2+(y-y_e)^2=r^2$.

d- extract local maxima in the 3D parameter space; they should correspond to the circles present in the original image

This algorithm has several limitations; in particular:

2- Modifications of the Standard Circle Hough Transform for our implementation

The current implementation makes use of modifications described in [2]. Here is a recall of the main modifications from the standard version:

3- Steps of the current implementation:

The current implementation executes the following steps:

a- compute the gradient images if necessary, respectively along x and y axis

b- compute the Hough image (or images, if the "phase coded" method has been chosen)

c- extract the circles centers from the Hough image(s). The way to proceed depends on the selected method:

d- compute the radius associated to each detected circle:

e- for each couple of too close circles, remove the one with the lower accumulation intensity in Hough image

4- How to use the input parameters of the algorithm

As a general rule, more the user will restrict the search parameters, the faster the algorithm will execute and the more accurate the result will be. Here are some details for each parameter:

nbMaxPtsPerCircle_example.png

5- Limitations of the current implementation:

As only one radius is associated to each circle center position, the current implementation does not allow to detect concentric circles.

References

[1] Hough transform. (2015, June 17). In Wikipedia, The Free Encyclopedia. Retrieved 15:42, June 29, 2015, from https://en.wikipedia.org/w/index.php?title=Hough_transform&oldid=667291656
[2] T.J. Atherton and D.J. Kerbyson, Size invariant circle detection, Image and Vision Computing 17 (1999) 795–803
[3] C. Kimme, D. Ballard, J. Sklansky, Finding circles by an array of accumulators, Proc. ACM 18 (1975) 120–122

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLFeatureDetection as fd

Code Example

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# radius range detection definition
radiusRange = PyIPSDK.createHoughCirclesRadiusRange(15, 20)
# hough circle detection computation
outHoughCircles2dPpties = fd.houghCircles2d(inImg, radiusRange)
# retrieve coordinates of first detected circle (associated to maximum intensity)
maxHoughCircles2dPpty = PyIPSDK.toPyDict(outHoughCircles2dPpties)['Coll'][0]
print("Circle with maximum accumulated intensity " + str(maxHoughCircles2dPpty['AccumIntensity'] ) + " found on coordinates x=" + str(maxHoughCircles2dPpty['X'] ) + " and y=" + str(maxHoughCircles2dPpty['Y'] ) + " and with radius=" + str(maxHoughCircles2dPpty['Radius'] ))

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLFeatureDetection/Processor/HoughCircles2d/HoughCircles2d.h>

Code Example

#include <IPSDKImageFile/Tiff/TiffImageFileUtils.h>
#include <IPSDKIPL/IPSDKIPLFeatureDetection/Processor/HoughCircles2d/HoughCircles2d.h>
// function returning the collection of circles with radii in a given range
// detected by Hough algorithm in the image loaded from a given TIFF file
boost::shared_ptr<imaproc::attr::HoughCircles2dPpties>
detectCircles(
const std::string& inImgFilePath,
ipUInt64 nMinRadius,
ipUInt64 nMaxRadius)
{
// load input image from file specified by the user
ipsdk::image::ImagePtr pInImg =
// apply Hough circles detection
const boost::shared_ptr<imaproc::attr::HoughCircles2dPpties> pCircles =
ipsdk::imaproc::fd::houghCircles2d(
pInImg,
// return the collection of detected circles
return pCircles;
}