Skip to content

expand_gray_refExpandGrayRefExpandGrayRefexpand_gray_refexpand_gray_refπŸ”—

Short descriptionπŸ”—

expand_gray_refExpandGrayRefExpandGrayRefexpand_gray_refexpand_gray_ref β€” Fill gaps between regions (depending on gray value or color) or split overlapping regions.

SignatureπŸ”—

expand_gray_ref( region Regions, image Image, region ForbiddenArea, out region RegionExpand, string Iterations, string Mode, integer RefGray, integer Threshold )void ExpandGrayRef( const HObject& Regions, const HObject& Image, const HObject& ForbiddenArea, HObject* RegionExpand, const HTuple& Iterations, const HTuple& Mode, const HTuple& RefGray, const HTuple& Threshold )static void HOperatorSet.ExpandGrayRef( HObject regions, HObject image, HObject forbiddenArea, out HObject regionExpand, HTuple iterations, HTuple mode, HTuple refGray, HTuple threshold )def expand_gray_ref( regions: HObject, image: HObject, forbidden_area: HObject, iterations: Union[int, str], mode: str, ref_gray: MaybeSequence[int], threshold: MaybeSequence[int] ) -> HObject

Herror expand_gray_ref( const Hobject Regions, const Hobject Image, const Hobject ForbiddenArea, Hobject* RegionExpand, const char* Iterations, const char* Mode, const Hlong RefGray, const Hlong Threshold )

Herror T_expand_gray_ref( const Hobject Regions, const Hobject Image, const Hobject ForbiddenArea, Hobject* RegionExpand, const Htuple Iterations, const Htuple Mode, const Htuple RefGray, const Htuple Threshold )

HRegion HImage::ExpandGrayRef( const HRegion& Regions, const HRegion& ForbiddenArea, const HTuple& Iterations, const HString& Mode, const HTuple& RefGray, const HTuple& Threshold ) const

HRegion HImage::ExpandGrayRef( const HRegion& Regions, const HRegion& ForbiddenArea, const HString& Iterations, const HString& Mode, Hlong RefGray, Hlong Threshold ) const

HRegion HImage::ExpandGrayRef( const HRegion& Regions, const HRegion& ForbiddenArea, const char* Iterations, const char* Mode, Hlong RefGray, Hlong Threshold ) const

HRegion HImage::ExpandGrayRef( const HRegion& Regions, const HRegion& ForbiddenArea, const wchar_t* Iterations, const wchar_t* Mode, Hlong RefGray, Hlong Threshold ) const (Windows only)

HRegion HRegion::ExpandGrayRef( const HImage& Image, const HRegion& ForbiddenArea, const HTuple& Iterations, const HString& Mode, const HTuple& RefGray, const HTuple& Threshold ) const

HRegion HRegion::ExpandGrayRef( const HImage& Image, const HRegion& ForbiddenArea, const HString& Iterations, const HString& Mode, Hlong RefGray, Hlong Threshold ) const

HRegion HRegion::ExpandGrayRef( const HImage& Image, const HRegion& ForbiddenArea, const char* Iterations, const char* Mode, Hlong RefGray, Hlong Threshold ) const

HRegion HRegion::ExpandGrayRef( const HImage& Image, const HRegion& ForbiddenArea, const wchar_t* Iterations, const wchar_t* Mode, Hlong RefGray, Hlong Threshold ) const (Windows only)

HRegion HImage.ExpandGrayRef( HRegion regions, HRegion forbiddenArea, HTuple iterations, string mode, HTuple refGray, HTuple threshold )

HRegion HImage.ExpandGrayRef( HRegion regions, HRegion forbiddenArea, string iterations, string mode, int refGray, int threshold )

HRegion HRegion.ExpandGrayRef( HImage image, HRegion forbiddenArea, HTuple iterations, string mode, HTuple refGray, HTuple threshold )

HRegion HRegion.ExpandGrayRef( HImage image, HRegion forbiddenArea, string iterations, string mode, int refGray, int threshold )

DescriptionπŸ”—

expand_gray_refExpandGrayRef closes gaps between the input regions, which resulted from the suppression of small regions in a segmentation operator, (mode 'image'"image"), for example, or separates overlapping regions 'region'"region"). Both uses result from the expansion of regions. The operator works by adding a one pixel wide β€œstrip” to a region, in which the gray values or color are different from a reference gray value or color by at most Thresholdthresholdthreshold (in each channel). For images of type 'cyclic'"cyclic" (e.g., direction images), also points with a gray value difference of at least \(255 - \textrm{Threshold}\) are added to the output region.

The expansion takes place only in regions, which are designated as not β€œforbidden” (parameter ForbiddenAreaforbiddenAreaforbidden_area). The number of iterations is determined by the parameter Iterationsiterationsiterations. By passing 'maximal'"maximal", expand_gray_refExpandGrayRef iterates until convergence, i.e., until no more changes occur. By passing 0 for this parameter, all non-overlapping regions are returned. The two modes of operation ('image'"image" and 'region'"region") are different in the following ways:

  • 'image'"image" The input regions are expanded iteratively until they touch another region or the image border, or the expansion stops because of too high gray value differences. Because expand_gray_refExpandGrayRef processes all regions simultaneously, gaps between regions are distributed evenly to all regions with a similar gray value. Overlapping regions are split by distributing the area of overlap evenly to both regions.

  • 'region'"region" No expansion of the input regions is performed. Instead, only overlapping regions are split by distributing the area of overlap evenly to regions having a matching gray value or color.

AttentionπŸ”—

Because regions are only expanded into areas having a matching gray value or color, usually gaps will remain between the output regions, i.e., the segmentation is not complete.

Execution informationπŸ”—

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

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

  • Processed without parallelization.

ParametersπŸ”—

Regionsregionsregions (input_object) region(-array) β†’ objectHObjectHRegionHObjectHobject

Regions for which the gaps are to be closed, or which are to be separated.

Imageimageimage (input_object) (multichannel-)image β†’ object (byte / cyclic)HObject (byte / cyclic)HImage (byte / cyclic)HObject (byte / cyclic)Hobject (byte / cyclic)

Image (possibly multi-channel) for gray value or color comparison.

ForbiddenAreaforbiddenAreaforbidden_area (input_object) region β†’ objectHObjectHRegionHObjectHobject

Regions in which no expansion takes place.

RegionExpandregionExpandregion_expand (output_object) region(-array) β†’ objectHObjectHRegionHObjectHobject *

Expanded or separated regions.

Iterationsiterationsiterations (input_control) string β†’ (string / integer)HTuple (HString / Hlong)HTuple (string / int / long)Union[int, str]Htuple (char* / Hlong)

Number of iterations.

Default: 'maximal'"maximal"
Suggested values: 'maximal', 1, 2, 3, 4, 5, 7, 10, 15, 20, 30, 50, 70, 100, 150, 200, 300, 500"maximal", 1, 2, 3, 4, 5, 7, 10, 15, 20, 30, 50, 70, 100, 150, 200, 300, 500
Value range: 1 ≀ Iterations ≀ 500 (lin)
Minimum increment: 1
Recommended increment: 1

Modemodemode (input_control) string β†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Expansion mode.

Default: 'image'"image"
List of values: 'image', 'region'"image", "region"

RefGrayrefGrayref_gray (input_control) integer(-array) β†’ (integer)HTuple (Hlong)HTuple (int / long)MaybeSequence[int]Htuple (Hlong)

Reference gray value or color for comparison.

Default: 128128
Suggested values: 1, 10, 20, 50, 100, 128, 200, 2551, 10, 20, 50, 100, 128, 200, 255
Value range: 1 ≀ RefGray ≀ 255 (lin)
Minimum increment: 1
Recommended increment: 10

Thresholdthresholdthreshold (input_control) integer(-array) β†’ (integer)HTuple (Hlong)HTuple (int / long)MaybeSequence[int]Htuple (Hlong)

Maximum difference between the reference gray value or color and a candidate for expansion.

Default: 3232
Suggested values: 4, 10, 15, 20, 25, 30, 404, 10, 15, 20, 25, 30, 40
Value range: 1 ≀ Threshold ≀ 255 (lin)
Minimum increment: 1
Recommended increment: 5

ExampleπŸ”—

(C)

read_image(&Image,"fabrik")\;
disp_image(Image,WindowHandle)\;
regiongrowing(Image,&RawSegments,3,3,6.0,100)\;
set_colored(WindowHandle,12)\;
disp_region(RawSegments,WindowHandle)\;
T_intensity(RawSegments,Image,&Mean,NULL)\;
set_i(Thresh,24,0)\;
set_s(Iter,"maximal",0)\;
set_s(Mode,"image",0)\;
T_expand_gray_ref(RawSegments,Image,EMPTY_REGION,&Segments,Iter,Mode,
               Mean,Thresh)\;
disp_region(Segments,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])\;
  HRegion  empty_region\;
  HWindow  win\;
 win.SetDraw ("margin")\;
  win.SetColored (12)\;
 image.Display (win)\;
 HRegionArray seg = (image >= 100).Connection ()\;
  seg.Display (win)\;
 Tuple iter = "maximal"\;
  Tuple mode = "image"\;
  Tuple refg = 128\;
  Tuple thrs = 32\;
 HRegionArray exp = seg.ExpandGrayRef (image, empty_region,
                                        iter, mode, refg, thrs)\;
  exp.Display (win)\;
  win.Click ()\;
 return (0)\;
}

ResultπŸ”—

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

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

connectionConnection, regiongrowingRegiongrowing, pouringPouring, class_ndim_normClassNdimNorm

Possible successors

select_shapeSelectShape

See also

expand_grayExpandGray, expand_regionExpandRegion

ModuleπŸ”—

Foundation