Skip to content

connectionConnectionConnectionconnectionconnection🔗

Short description🔗

connectionConnectionConnectionconnectionconnection — Compute connected components of a region.

Signature🔗

connection( region Region, out region ConnectedRegions )void Connection( const HObject& Region, HObject* ConnectedRegions )static void HOperatorSet.Connection( HObject region, out HObject connectedRegions )def connection( region: HObject ) -> HObject

Herror connection( const Hobject Region, Hobject* ConnectedRegions )

Herror T_connection( const Hobject Region, Hobject* ConnectedRegions )

HRegion HRegion::Connection( ) const

HRegion HRegion.Connection( )

Description🔗

connectionConnection determines the connected components of the input regions given in Regionregionregion. The neighborhood used for this can be set via set_system('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 connectionConnection can be set via set_system('max_connection',<Num>). The default value of 00 causes all connected components to be returned. The inverse operator of connectionConnection is union1Union1.

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 internal data level.

Parameters🔗

Regionregionregion (input_object) region(-array) → objectHObjectHRegionHObjectHobject

Input region.

ConnectedRegionsconnectedRegionsconnected_regions (output_object) region-array → objectHObjectHRegionHObjectHobject *

Connected components.

Example🔗

(HDevelop)

read_image(Image,'clip')
dev_set_colored(12)
threshold(Image,Dark,0,150)
count_obj(Dark,NumThresholded)
dev_display (Dark)
connection(Dark,ConnectedRegions)
count_obj(ConnectedRegions,NumConnected)
dev_display (ConnectedRegions)
(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)\;
(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)\;
}

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🔗

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

Combinations with other operators🔗

Combinations

Possible predecessors

auto_thresholdAutoThreshold, thresholdThreshold, dyn_thresholdDynThreshold, erosion1Erosion1

Possible successors

select_shapeSelectShape, select_graySelectGray, shape_transShapeTrans, set_coloredSetColored, dilation1Dilation1, count_objCountObj, reduce_domainReduceDomain, add_channelsAddChannels

Alternatives

background_segBackgroundSeg

See also

set_systemSetSystem, union1Union1

Module🔗

Foundation