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

connectionconnectionconnectionConnectionConnection (Operator)

Name

connectionconnectionconnectionConnectionConnection — Compute connected components of a region.

Signature

connection(Region : ConnectedRegions : : )

Herror connection(const Hobject Region, Hobject* ConnectedRegions)

Herror T_connection(const Hobject Region, Hobject* ConnectedRegions)

Herror connection(Hobject Region, Hobject* ConnectedRegions)

HRegionArray HRegion::Connection() const

HRegionArray HRegionArray::Connection() const

void HOperatorSetX.Connection(
[in] IHUntypedObjectX* Region, [out] IHUntypedObjectX*ConnectedRegions)

IHRegionX* HRegionX.Connection()

static void HOperatorSet.Connection(HObject region, out HObject connectedRegions)

HRegion HRegion.Connection()

Description

connectionconnectionconnectionConnectionConnection determines the connected components of the input regions given in RegionRegionRegionRegionregion. The neighborhood used for this can be set via set_system('neighborhood',<4/8>)set_system("neighborhood",<4/8>)set_system("neighborhood",<4/8>)SetSystem("neighborhood",<4/8>)SetSystem("neighborhood",<4/8>). The default is 8-neighborhood, which is useful for determining the connected components of the foreground. The maximum number of connected components that is returned by connectionconnectionconnectionConnectionConnection can be set via set_system('max_connection',<Num>)set_system("max_connection",<Num>)set_system("max_connection",<Num>)SetSystem("max_connection",<Num>)SetSystem("max_connection",<Num>). The default value of 0 causes all connected components to be returned. The inverse operator of connectionconnectionconnectionConnectionConnection is union1union1union1Union1Union1.

Parallelization

Parameters

RegionRegionRegionRegionregion (input_object)  region(-array) objectHRegionHRegionHRegionXHobject

Input region.

ConnectedRegionsConnectedRegionsConnectedRegionsConnectedRegionsconnectedRegions (output_object)  region-array objectHRegionHRegionArrayHRegionXHobject *

Connected components.

Example (HDevelop)

read_image(Image,'monkey')
set_colored(WindowHandle,12)
threshold(Image,Light,150.0,255.0)
count_obj(Light,Number1)
fwrite_string(FH, 'Number of regions after threshold = '+Number1)
fnew_line(FH)
disp_region(Light,WindowHandle)
connection(Light,Many)
count_obj(Many,Number2)
fwrite_string(FH, 'Number of regions after threshold = '+Number2)
fnew_line(FH)
disp_region(Many,WindowHandle)

Example (C)

read_image(&Image,"monkey");
set_colored(WindowHandle,12);
threshold(Image,&Light,150.0,255.0);
count_obj(Light,&Number1);
printf("Number of regions after threshold = %d\n",Number1);
disp_region(Light,WindowHandle);
connection(Light,&Many);
count_obj(Many,&Number2);
printf("Number of regions after threshold = %d\n",Number2);
disp_region(Many,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[])
{
  HImage   image (argv[1]);
  HWindow  w;
  w.SetColored(12);
  HRegion Light = image >= 128;
  Light.Display(w);
  HRegionArray Many = Light.Connection();
  cout << "Number of regions after threshold = " << Many.Num();
  Many.Display(w);
}

Example (HDevelop)

read_image(Image,'monkey')
set_colored(WindowHandle,12)
threshold(Image,Light,150.0,255.0)
count_obj(Light,Number1)
fwrite_string(FH, 'Number of regions after threshold = '+Number1)
fnew_line(FH)
disp_region(Light,WindowHandle)
connection(Light,Many)
count_obj(Many,Number2)
fwrite_string(FH, 'Number of regions after threshold = '+Number2)
fnew_line(FH)
disp_region(Many,WindowHandle)

Example (HDevelop)

read_image(Image,'monkey')
set_colored(WindowHandle,12)
threshold(Image,Light,150.0,255.0)
count_obj(Light,Number1)
fwrite_string(FH, 'Number of regions after threshold = '+Number1)
fnew_line(FH)
disp_region(Light,WindowHandle)
connection(Light,Many)
count_obj(Many,Number2)
fwrite_string(FH, 'Number of regions after threshold = '+Number2)
fnew_line(FH)
disp_region(Many,WindowHandle)

Complexity

Let F be the area of the input region and N be the number of generated connected components. Then the runtime complexity is O(sqrt(F) * sqrt(N)).

Result

connectionconnectionconnectionConnectionConnection always returns the value 2 (H_MSG_TRUE). The behavior in case of empty input (no regions given) can be set via 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>) and the behavior in case of an empty input region 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

auto_thresholdauto_thresholdauto_thresholdAutoThresholdAutoThreshold, thresholdthresholdthresholdThresholdThreshold, dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold, erosion1erosion1erosion1Erosion1Erosion1

Possible Successors

select_shapeselect_shapeselect_shapeSelectShapeSelectShape, select_grayselect_grayselect_graySelectGraySelectGray, shape_transshape_transshape_transShapeTransShapeTrans, set_coloredset_coloredset_coloredSetColoredSetColored, dilation1dilation1dilation1Dilation1Dilation1, count_objcount_objcount_objCountObjCountObj, reduce_domainreduce_domainreduce_domainReduceDomainReduceDomain, add_channelsadd_channelsadd_channelsAddChannelsAddChannels

Alternatives

background_segbackground_segbackground_segBackgroundSegBackgroundSeg

See also

set_systemset_systemset_systemSetSystemSetSystem, union1union1union1Union1Union1

Module

Foundation


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