HALCON Reference Manual 10.0.2
Table of Contents / Regions / Features ClassesClassesClasses | | | Operators

smallest_circlesmallest_circlesmallest_circleSmallestCircleSmallestCircle (Operator)

Name

smallest_circlesmallest_circlesmallest_circleSmallestCircleSmallestCircle — Smallest surrounding circle of a region.

Signature

smallest_circle(Regions : : : Row, Column, Radius)

Herror smallest_circle(const Hobject Regions, double* Row, double* Column, double* Radius)

Herror T_smallest_circle(const Hobject Regions, Htuple* Row, Htuple* Column, Htuple* Radius)

Herror smallest_circle(Hobject Regions, double* Row, double* Column, double* Radius)

Herror smallest_circle(Hobject Regions, HTuple* Row, HTuple* Column, HTuple* Radius)

double HRegion::SmallestCircle(double* Column, double* Radius) const

HTuple HRegionArray::SmallestCircle(HTuple* Column, HTuple* Radius) const

void HOperatorSetX.SmallestCircle(
[in] IHUntypedObjectX* Regions, [out] VARIANT* Row, [out] VARIANT* Column, [out] VARIANT* Radius)

VARIANT HRegionX.SmallestCircle(
[out] VARIANT* Column, [out] VARIANT* Radius)

static void HOperatorSet.SmallestCircle(HObject regions, out HTuple row, out HTuple column, out HTuple radius)

void HRegion.SmallestCircle(out HTuple row, out HTuple column, out HTuple radius)

void HRegion.SmallestCircle(out double row, out double column, out double radius)

Description

The operator smallest_circlesmallest_circlesmallest_circleSmallestCircleSmallestCircle determines the smallest surrounding circle of a region, i.e., the circle with the smallest area of all circles containing the region. For this circle the center (RowRowRowRowrow,ColumnColumnColumnColumncolumn) and the radius (RadiusRadiusRadiusRadiusradius) are calculated. The operator is applied when, for example, the location and size of circular objects (e.g., coins) which, however, are not homogeneous inside or have broken edges due to bad segmentation, has to be determined. The output of the operator is selected in such a way that it can be used as input for the operators disp_circledisp_circledisp_circleDispCircleDispCircle and gen_circlegen_circlegen_circleGenCircleGenCircle.

If several regions are passed in RegionsRegionsRegionsRegionsregions corresponding tuples are returned as output parameter. In case of empty region all parameters have the value 0.0 if no other behavior was set (see set_systemset_systemset_systemSetSystemSetSystem).

Attention

Internally, the calculation is based on the center coordinates of the region pixels. To take into account that pixels are not just infinitely small points but have a certain area, the calculated radius is enlarged by 0.5 before it is returned in RadiusRadiusRadiusRadiusradius. This, in most cases, gives acceptable results. However, in the worst case (pixel diagonal) this enlargement is not sufficient. If one wants to ensure that the border of the input region completely lies within the circle, one had to enlarge the radius by 1/sqrt(2) instead of 0.5. Consequently, the value returned in RadiusRadiusRadiusRadiusradius must be corrected by 1/sqrt(2)-0.5. However, this would also be only an upper bound, i.e., the circle with the corrected radius would be slightly too big in most cases.

Parallelization

Parameters

RegionsRegionsRegionsRegionsregions (input_object)  region(-array) objectHRegionHRegionHRegionXHobject

Regions to be examined.

RowRowRowRowrow (output_control)  circle.center.y(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Line index of the center.

ColumnColumnColumnColumncolumn (output_control)  circle.center.x(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Column index of the center.

RadiusRadiusRadiusRadiusradius (output_control)  circle.radius(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Radius of the surrounding circle.

Assertion: Radius >= 0

Example (HDevelop)

read_image(Image,'fabrik')
open_window(0,0,-1,-1,'root','visible','',WindowHandle)
regiongrowing(Image,Seg,5,5,6,100)
select_shape(Seg,H,'area','and',100,2000)
smallest_circle(H,Row,Column,Radius)
gen_circle(Circles,Row,Column,Radius)
set_draw(WindowHandle,'margin')
disp_region(Circles,WindowHandle)

Example (C)

read_image(&Image,"fabrik");
open_window(0,0,-1,-1,0,"visible","",&WindowHandle);
regiongrowing(Image,&Seg,5,5,6.0,100);
select_shape(Seg,&H,"area","and",100.0,2000.0);
T_smallest_circle(H,&Row,&Column,&Radius);
T_gen_circle(&Circles,Row,Column,Radius);
set_draw(WindowHandle,"margin");
disp_region(Circles,WindowHandle);

Example (C++)

#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"
using namespace Halcon;

int main (int argc, char *argv[])
{
  Tuple    row, col, rad;

  HImage   img (argv[1]);
  HWindow  w;

  img.Display (w);

  HRegionArray  reg  = img.Regiongrowing (5, 5, 6.0, 100);
  HRegionArray  seg  = reg.SelectShape ("area", "and", 100.0, 1000.0);

  row = seg.SmallestCircle (&col, &rad);

  HRegionArray  circ = HRegionArray::GenCircle (row, col, rad);

  w.SetDraw   ("margin");

  w.SetColor  ("green");   reg.Display (w);
  w.SetColor  ("blue");    seg.Display (w);
  w.SetColor  ("red");     circ.Display (w);
  w.Click ();

  return(0);
}

Example (HDevelop)

read_image(Image,'fabrik')
open_window(0,0,-1,-1,'root','visible','',WindowHandle)
regiongrowing(Image,Seg,5,5,6,100)
select_shape(Seg,H,'area','and',100,2000)
smallest_circle(H,Row,Column,Radius)
gen_circle(Circles,Row,Column,Radius)
set_draw(WindowHandle,'margin')
disp_region(Circles,WindowHandle)

Example (HDevelop)

read_image(Image,'fabrik')
open_window(0,0,-1,-1,'root','visible','',WindowHandle)
regiongrowing(Image,Seg,5,5,6,100)
select_shape(Seg,H,'area','and',100,2000)
smallest_circle(H,Row,Column,Radius)
gen_circle(Circles,Row,Column,Radius)
set_draw(WindowHandle,'margin')
disp_region(Circles,WindowHandle)

Complexity

If F is the area of the region, then the mean runtime complexity is O(sqrt(F).

Result

The operator smallest_circlesmallest_circlesmallest_circleSmallestCircleSmallestCircle returns the value 2 (H_MSG_TRUE) if the input is not empty. The behavior in case of empty input (no input regions available) is set via the operator set_system('no_object_result',<Result>)set_system("no_object_result",<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>). The behavior in case of empty region (the region is the empty set) is set via set_system('empty_region_result',<Result>)set_system("empty_region_result",<Result>)set_system("empty_region_result",<Result>)SetSystem("empty_region_result",<Result>)SetSystem("empty_region_result",<Result>). If necessary an exception is raised.

Possible Predecessors

thresholdthresholdthresholdThresholdThreshold, regiongrowingregiongrowingregiongrowingRegiongrowingRegiongrowing, connectionconnectionconnectionConnectionConnection, runlength_featuresrunlength_featuresrunlength_featuresRunlengthFeaturesRunlengthFeatures

Possible Successors

gen_circlegen_circlegen_circleGenCircleGenCircle, disp_circledisp_circledisp_circleDispCircleDispCircle

Alternatives

elliptic_axiselliptic_axiselliptic_axisEllipticAxisEllipticAxis, smallest_rectangle1smallest_rectangle1smallest_rectangle1SmallestRectangle1SmallestRectangle1, smallest_rectangle2smallest_rectangle2smallest_rectangle2SmallestRectangle2SmallestRectangle2

See also

set_shapeset_shapeset_shapeSetShapeSetShape, select_shapeselect_shapeselect_shapeSelectShapeSelectShape, inner_circleinner_circleinner_circleInnerCircleInnerCircle

Module

Foundation


Table of Contents / Regions / Features ClassesClassesClasses | | | Operators
HALCON Reference Manual 10.0.2 Copyright © 1996-2011 MVTec Software GmbH