Skip to content

circularityCircularityCircularitycircularitycircularityπŸ”—

Short descriptionπŸ”—

circularityCircularityCircularitycircularitycircularity β€” Shape factor for the circularity (similarity to a circle) of a region.

SignatureπŸ”—

circularity( region Regions, out real Circularity )void Circularity( const HObject& Regions, HTuple* Circularity )static void HOperatorSet.Circularity( HObject regions, out HTuple circularity )def circularity( regions: HObject ) -> Sequence[float]

def circularity_s( regions: HObject ) -> floatHerror circularity( const Hobject Regions, double* Circularity )

Herror T_circularity( const Hobject Regions, Htuple* Circularity )

HTuple HRegion::Circularity( ) const

HTuple HRegion.Circularity( )

DescriptionπŸ”—

The operator circularityCircularity calculates the similarity of the input region with a circle.

  • Calculation: If F is the area of the region and max is the maximum distance from the center to all contour pixels, the shape factor C is defined as:

    \[\begin{eqnarray*} C^\prime = \frac{F}{(max^2 * \pi)} \end{eqnarray*}\]

    C = min(1,C’)

The shape factor C of a circle is 1. If the region is long or has holes, C is smaller than 1. The operator circularityCircularity especially responds to large bulges, holes and unconnected regions. The value of C is clipped to 1.0, because the pixel area of a region can only be an approximation of a real circle’s area. This approximation error is bigger for small regions than for large regions.

In the documentation of this chapter (Regions / Features), you can find an image illustrating regions which vary in their circularity.

In case of an empty region the operator circularityCircularity returns the value 0 (if no other behavior was set (see set_systemSetSystem)). If more than one region is passed the numerical values of the shape factor are stored in a tuple, the position of a value in the tuple corresponding to the position of the region in the input tuple.

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Automatically parallelized on tuple level.

ParametersπŸ”—

Regionsregionsregions (input_object) region(-array) β†’ objectHObjectHRegionHObjectHobject

Region(s) to be examined.

Circularitycircularitycircularity (output_control) real(-array) β†’ (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Circularity of the input region(s).

Assertion: 0 <= Circularity && Circularity <= 1.0

ExampleπŸ”—

(HDevelop)

* Comparison between shape factors of rectangle, circle and ellipse:
gen_rectangle1(R1,10,10,20,20)
gen_rectangle2(R2,100,100,0.0,100,20)
gen_ellipse(E100,100,100,0.0,100,20)
gen_circle(C,100,100,20)
circularity(R1,M_R1)
circularity(R2,M_R2)
circularity(E100,M_E)
circularity(C,M_C)
fwrite_string(FileId,['quadrate:  ',M_R1])
fnew_line(FileId)
fwrite_string(FileId,['rectangle: ',M_R2])
fnew_line(FileId)
fwrite_string(FileId,['ellipse:   ',M_E])
fnew_line(FileId)
fwrite_string(FileId,['circle:    ',M_C])
fnew_line(FileId)
(C)
/* Comparison between shape factors of rectangle, circle and ellipse */
gen_rectangle1(&R1,10.0,10.0,20.0,20.0)\;
gen_rectangle2(&R2,100.0,100.0,0.0,100.0,20.0)\;
gen_ellipse(&E,100.0,100.0,0.0,100.0,20.0)\;
gen_circle(&C,100.0,100.0,20.0)\;
circularity(R1,&R1_)\;
circularity(R2,&R2_)\;
circularity(E,&E_)\;
circularity(C,&C_)\;
printf("quadrate:   %g\n",R1_)\;
printf("rectangle:  %g\n",R2_)\;
printf("ellipse:    %g\n",E_)\;
printf("circle:     %g\n",C_)\;
(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[])
{
  if (argc < 2)
  {
    cout << "Usage: " << argv[0] << " <# of regions> " << endl\;
    return (-1)\;
  }
 HWindow        w\;
  HRegionArray   reg\;
 int NumOfElements = atoi (argv[1])\;
 cout << "Draw " << NumOfElements << " regions " << endl\;
 for (int i=0\; i < NumOfElements\; i++)
  {
    reg[i] = w.DrawRegion ()\;
  }
 Tuple circ = reg.Circularity ()\;
  Tuple cont = reg.Contlength ()\;
 for (i = 0\; i < NumOfElements\; i++)
  {
    cout << "Circularity of " << i+1 << ". region = " << circ[i].D()\;
    cout << "\t\t Contour Length of" << i+1 <<
            ". region = " << cont[i].D() << endl\;
  }
 w.Click ()\;
  return(0)\;
}

ResultπŸ”—

The operator circularityCircularity 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>). The behavior in case of empty region (the region is the empty set) is set via set_system('empty_region_result',<Result>). If necessary an exception is raised.

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

thresholdThreshold, regiongrowingRegiongrowing, connectionConnection

Alternatives

roundnessRoundness, compactnessCompactness, convexityConvexity, eccentricityEccentricity

See also

area_centerAreaCenter, select_shapeSelectShape

ModuleπŸ”—

Foundation