Skip to content

openingOpeningOpeningopeningopening🔗

Short description🔗

openingOpeningOpeningopeningopening — Open a region.

Signature🔗

opening( region Region, region StructElement, out region RegionOpening )void Opening( const HObject& Region, const HObject& StructElement, HObject* RegionOpening )static void HOperatorSet.Opening( HObject region, HObject structElement, out HObject regionOpening )def opening( region: HObject, struct_element: HObject ) -> HObject

Herror opening( const Hobject Region, const Hobject StructElement, Hobject* RegionOpening )

Herror T_opening( const Hobject Region, const Hobject StructElement, Hobject* RegionOpening )

HRegion HRegion::Opening( const HRegion& StructElement ) const

HRegion HRegion.Opening( HRegion structElement )

Description🔗

An openingOpening operation is defined as an erosion followed by a Minkowski addition. By applying openingOpening to a region, larger structures remain mostly intact, while small structures like lines or points are eliminated. In contrast, a closingClosing operation results in small gaps being retained or filled up (see closingClosing).

openingOpening serves to eliminate small regions (smaller than StructElementstructElementstruct_element) and to smooth the boundaries of a region. The position of StructElementstructElementstruct_element is meaningless, since an opening operation is invariant with respect to the choice of the reference point.

Structuring elements (StructElementstructElementstruct_element) can be generated with operators such as gen_circleGenCircle, gen_rectangle1GenRectangle1, gen_rectangle2GenRectangle2, gen_ellipseGenEllipse, draw_regionDrawRegion, gen_region_polygonGenRegionPolygon, gen_region_pointsGenRegionPoints, etc.

Execution information🔗

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

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

Parameters🔗

Regionregionregion (input_object) region(-array) → objectHObjectHRegionHObjectHobject

Regions to be opened.

StructElementstructElementstruct_element (input_object) region → objectHObjectHRegionHObjectHobject

Structuring element (position-invariant).

RegionOpeningregionOpeningregion_opening (output_object) region(-array) → objectHObjectHRegionHObjectHobject *

Opened regions.

Example🔗

(HDevelop)

* Large regions in an aerial picture (beech trees or meadows):
read_image(Image,'forest_road')
threshold(Image,Light,160,255)
gen_circle(StructElement,100,100,10)
* selecting the large regions
opening(Light,StructElement,Large)
* Selecting of edges with certain orientation:
read_image(Image,'fabrik')
sobel_amp(Image,Sobel,'sum_abs',3)
threshold(Sobel,Edges,10,255)
gen_rectangle2(StructElement,100,100,3.07819,20,1)
opening(Edges,StructElement,Direction)
(C)
/* simulation of opening */
my_opening(Hobject In, Hobject StructElement, Hobject *Out)
{
  Hobject  H\;
  erosion1(In,StructElement,&H,1)\;
  minkowski_add1(H,StructElement,Out,1)\;
}

/* Large regions in an aerial picture (beech trees or meadows): */
read_image(&Image,"forest_road")\;
threshold(Image,&Light,160.0,255.0)\;
gen_circle(&StructElement,100.0,100.0,10.0)\;
/* selecting the large regions */
opening(Light,StructElement,&Large)\;

/* Selecting of edges with certain orientation: */
read_image(&Image,"fabrik")\;
sobel_amp(Image,&Sobel,"sum_abs",3)\;
threshold(Sobel,Edges,30.0,255.0)\;
gen_rectangle2(&StructElement,100.0,100.0,3.07819,20.0,1.0)\;
opening(Edges,StructElement,&Direction)\;
(C++)
#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std\;
#endif
#include "HalconCpp.h"

main()
{
  HImage     img("forest_road")\;
  HWindow    w\;
 cout << "Example: Large regions in an aerial picture: " << endl\;
  cout << "Beech Trees or Meadows" << endl\;
 /* Struct elements */
  HRegion      circ1  = HRegion::GenCircle (10, 10, 10)\;
  HRegion      rect1  = HRegion::GenRectangle2 (100, 100, 3.07819, 20, 1)\;
 /* Segmentation, opening () -> select large regions */
  HRegionArray regs   = (img >= 160).Connection()\;
  HRegionArray open   = regs.Opening (circ1)\;
                       img.Display (w)\;    w.Click ()\;
  w.SetColor ("red")\;   regs.Display (w)\;   w.Click ()\;
  w.SetColor ("green")\; open.Display (w)\;   w.Click ()\;
 cout << "Example: Selecting of edges with certain orientation" << endl\;
 HByteImage hbi ("fabrik")\;
 HImage  sobel = hbi.SobelAmp ("sum_abs", 3)\;
  regs = (sobel >= 30).Connection ()\;
 HRegionArray direc = regs.Opening (rect1)\;
                       hbi.Display (w)\;    w.Click ()\;
  w.SetColor ("red")\;   regs.Display (w)\;   w.Click ()\;
  w.SetColor ("blue")\;  sobel.Display (w)\;  w.Click ()\;
  w.SetColor ("green")\; direc.Display (w)\;  w.Click ()\;
 return(0)\;
}

Complexity🔗

Let \(F1\) be the area of the input region, and \(F2\) be the area of the structuring element. Then the runtime complexity for one region is:

\[\begin{eqnarray*} O(2 \cdot \sqrt{F1} \cdot \sqrt{F2}) \enspace . \end{eqnarray*}\]

Result🔗

openingOpening returns 2 (H_MSG_TRUE) if all parameters are correct. The behavior in case of empty or no input region can be set via:

  • no region: set_system('no_object_result',<RegionResult>)

  • empty region: set_system('empty_region_result',<RegionResult>)

Otherwise, an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

thresholdThreshold, regiongrowingRegiongrowing, connectionConnection, union1Union1, watershedsWatersheds, class_ndim_normClassNdimNorm, gen_circleGenCircle, gen_ellipseGenEllipse, gen_rectangle1GenRectangle1, gen_rectangle2GenRectangle2, draw_regionDrawRegion, gen_region_pointsGenRegionPoints, gen_region_polygon_filledGenRegionPolygonFilled

Possible successors

reduce_domainReduceDomain, select_shapeSelectShape, area_centerAreaCenter, connectionConnection

Alternatives

minkowski_add1MinkowskiAdd1, erosion1Erosion1, opening_circleOpeningCircle

See also

gen_circleGenCircle, gen_rectangle2GenRectangle2, gen_region_polygonGenRegionPolygon

Module🔗

Foundation