Herror ::circularity (
    Hobject Regions,
    double *Circularity
)
Herror ::circularity (
    Hobject Regions,
    HTuple *Circularity
)
double HRegion::Circularity (
    void
) const
HTuple HRegionArray::Circularity (
    void
) const

Shape factor for the roundness of a region.

The operator ::circularity calculates the compactness of the input region.

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:
                               C = F / (max^2 * pi)
The shape factor C of a circle is 1. If the region is long or has holes C is smaller than 1. The operator ::circularity especially responds to large bulges, holes and unconnected regions.

In case of an empty region the operator ::circularity returns the value 0 (if no other behavior was set (see ::set_system)). 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.


Parameters

Regions (input_object)
region(-array) -> Hobject: HRegion(Array)
Region(s) to be examined.

Circularity (output_control)
real(-array) -> (HTuple.) double *
Roundness of the input region(s).
Assertion: (0 <= Circularity) && (Circularity <= 1.0)


Example
#include  <iostream.h>
#include  "HalconCpp.h"

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 ::circularity returns the value 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 handling is raised.


Possible Predecessors

::threshold, ::regiongrowing, ::connection


Alternatives

::compactness, ::convexity, ::eccentricity


See also

::area_center, ::select_shape


Module

Region processing



Copyright © 1996-2002 MVTec Software GmbH