Operator Reference

closingclosingClosingClosingclosing (Operator)

closingclosingClosingClosingclosing — Close a region.

Signature

Herror closing(const Hobject Region, const Hobject StructElement, Hobject* RegionClosing)

Herror T_closing(const Hobject Region, const Hobject StructElement, Hobject* RegionClosing)

void Closing(const HObject& Region, const HObject& StructElement, HObject* RegionClosing)

HRegion HRegion::Closing(const HRegion& StructElement) const

def closing(region: HObject, struct_element: HObject) -> HObject

Description

A closingclosingClosingClosingclosing operation is defined as a dilation followed by a Minkowski subtraction. By applying closingclosingClosingClosingclosing to a region, larger structures remain mostly intact, while small gaps between adjacent regions and holes smaller than StructElementStructElementStructElementstructElementstruct_element are closed, and the regions' boundaries are smoothed. All closingclosingClosingClosingclosing variants share the property that separate regions are not merged, but remain separate objects. The position of StructElementStructElementStructElementstructElementstruct_element is meaningless, since a closing operation is invariant with respect to the choice of the reference point.

Structuring elements (StructElementStructElementStructElementstructElementstruct_element) can be generated with operators such as gen_circlegen_circleGenCircleGenCirclegen_circle, gen_rectangle1gen_rectangle1GenRectangle1GenRectangle1gen_rectangle1, gen_rectangle2gen_rectangle2GenRectangle2GenRectangle2gen_rectangle2, gen_ellipsegen_ellipseGenEllipseGenEllipsegen_ellipse, draw_regiondraw_regionDrawRegionDrawRegiondraw_region, gen_region_polygongen_region_polygonGenRegionPolygonGenRegionPolygongen_region_polygon, gen_region_pointsgen_region_pointsGenRegionPointsGenRegionPointsgen_region_points, etc.

Attention

closingclosingClosingClosingclosing is applied to each input region separately. If gaps between different regions are to be closed, union1union1Union1Union1union1 or union2union2Union2Union2union2 has to be called first.

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

RegionRegionRegionregionregion (input_object)  region(-array) objectHRegionHObjectHObjectHobject

Regions to be closed.

StructElementStructElementStructElementstructElementstruct_element (input_object)  region objectHRegionHObjectHObjectHobject

Structuring element (position-invariant).

RegionClosingRegionClosingRegionClosingregionClosingregion_closing (output_object)  region(-array) objectHRegionHObjectHObjectHobject *

Closed regions.

Example (C++)

#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"

main()
{
  cout << "Reproduction of 'closing ()' using " << endl;
  cout << "'dilation()' and 'minkowski_sub1()'" << endl;

  HByteImage img("monkey");
  HWindow    w;

  HRegion      circ = HRegion::GenCircle (10, 10, 1.5);
  HRegionArray regs = (img >= 128).Connection();

  HRegionArray dilreg = regs.Dilation1 (circ, 1);
  HRegionArray minsub = dilreg.MinkowskiSub1 (circ, 1);

                        img.Display (w);      w.Click ();
  w.SetColor ("red");   regs.Display (w);     w.Click ();
  w.SetColor ("green"); dilreg.Display (w);   w.Click ();
  w.SetColor ("blue");  minsub.Display (w);   w.Click ();

  return(0);
}

Example (C)

my_closing(Hobject In, Hobject StructElement, Hobject *Out)
{
  Hobject  tmp;
  dilation1(In,StructElement,&tmp,1);
  minkowski_sub1(tmp,StructElement,Out,1);
}

Example (C++)

#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"

main()
{
  cout << "Reproduction of 'closing ()' using " << endl;
  cout << "'dilation()' and 'minkowski_sub1()'" << endl;

  HByteImage img("monkey");
  HWindow    w;

  HRegion      circ = HRegion::GenCircle (10, 10, 1.5);
  HRegionArray regs = (img >= 128).Connection();

  HRegionArray dilreg = regs.Dilation1 (circ, 1);
  HRegionArray minsub = dilreg.MinkowskiSub1 (circ, 1);

                        img.Display (w);      w.Click ();
  w.SetColor ("red");   regs.Display (w);     w.Click ();
  w.SetColor ("green"); dilreg.Display (w);   w.Click ();
  w.SetColor ("blue");  minsub.Display (w);   w.Click ();

  return(0);
}

Example (C++)

#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"

main()
{
  cout << "Reproduction of 'closing ()' using " << endl;
  cout << "'dilation()' and 'minkowski_sub1()'" << endl;

  HByteImage img("monkey");
  HWindow    w;

  HRegion      circ = HRegion::GenCircle (10, 10, 1.5);
  HRegionArray regs = (img >= 128).Connection();

  HRegionArray dilreg = regs.Dilation1 (circ, 1);
  HRegionArray minsub = dilreg.MinkowskiSub1 (circ, 1);

                        img.Display (w);      w.Click ();
  w.SetColor ("red");   regs.Display (w);     w.Click ();
  w.SetColor ("green"); dilreg.Display (w);   w.Click ();
  w.SetColor ("blue");  minsub.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:

Result

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

Otherwise, an exception is raised.

Possible Predecessors

thresholdthresholdThresholdThresholdthreshold, regiongrowingregiongrowingRegiongrowingRegiongrowingregiongrowing, connectionconnectionConnectionConnectionconnection, union1union1Union1Union1union1, watershedswatershedsWatershedsWatershedswatersheds, class_ndim_normclass_ndim_normClassNdimNormClassNdimNormclass_ndim_norm, gen_circlegen_circleGenCircleGenCirclegen_circle, gen_ellipsegen_ellipseGenEllipseGenEllipsegen_ellipse, gen_rectangle1gen_rectangle1GenRectangle1GenRectangle1gen_rectangle1, gen_rectangle2gen_rectangle2GenRectangle2GenRectangle2gen_rectangle2, draw_regiondraw_regionDrawRegionDrawRegiondraw_region, gen_region_pointsgen_region_pointsGenRegionPointsGenRegionPointsgen_region_points, gen_region_polygon_filledgen_region_polygon_filledGenRegionPolygonFilledGenRegionPolygonFilledgen_region_polygon_filled

Possible Successors

reduce_domainreduce_domainReduceDomainReduceDomainreduce_domain, select_shapeselect_shapeSelectShapeSelectShapeselect_shape, area_centerarea_centerAreaCenterAreaCenterarea_center, connectionconnectionConnectionConnectionconnection

Alternatives

closing_circleclosing_circleClosingCircleClosingCircleclosing_circle

See also

dilation1dilation1Dilation1Dilation1dilation1, erosion1erosion1Erosion1Erosion1erosion1, openingopeningOpeningOpeningopening, minkowski_sub1minkowski_sub1MinkowskiSub1MinkowskiSub1minkowski_sub1

Module

Foundation