Herror ::expand_gray (
    Hobject Regions,
    Hobject Image,
    Hobject ForbiddenArea,
    Hobject *RegionExpand,
    const HTuple &Iterations,
    const HTuple &Mode,
    const HTuple &Threshold
)
HRegion HRegion::ExpandGray (
    const HImage &Image,
    const HRegion &ForbiddenArea,
    const HTuple &Iterations,
    const HTuple &Mode,
    const HTuple &Threshold
) const
HRegionArray HRegionArray::ExpandGray (
    const HImage &Image,
    const HRegion &ForbiddenArea,
    const HTuple &Iterations,
    const HTuple &Mode,
    const HTuple &Threshold
) const

Fill gaps between regions (depending on gray value or color) or split overlapping regions.

::expand_gray closes gaps between the input regions, which resulted from the suppression of small regions in a segmentation operator, (mode 'image'), for example, or separates overlapping regions '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 the gray values or color of neighboring pixles on the region's border by at most Threshold (in each channel). For images of type 'cyclic' (e.g., direction images), also points with a gray value difference of at least 255 - Threshold are added to the output region.

The expansion takes place only in regions, which are designated as not ``forbidden'' (parameter ForbiddenArea). The number of iterations is determined by the parameter Iterations. By passing 'maximal', ::expand_gray 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' and 'region') are different in the following ways:

  '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 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'
          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.


Parameters

Regions (input_object)
region(-array) -> Hobject: HRegion(Array)
Regions for which the gaps are to be closed, or which are to be separated.

Image (input_object)
image -> Hobject: HImage
Image (possibly multi-channel) for gray value or color comparison.

ForbiddenArea (input_object)
region -> Hobject: HRegion
Regions in which no expansion takes place.

RegionExpand (output_object)
region(-array) -> Hobject * : HRegion(Array)
Expanded or separated regions.

Iterations (input_control)
string -> HTuple.char * / long
Number of iterations.
Default value: 'maximal'
Suggested values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'maximal'
Typical range of values: 1 <= Iterations <= 500 (lin)
Minimum increment: 1
Recommended increment: 1

Mode (input_control)
string -> HTuple.char *
Expansion mode.
Default value: 'image'
List of values: 'image', 'region'

Threshold (input_control)
integer(-array) -> HTuple.long
Maximum difference between the gray value or color at the region's border and a candidate for expansion.
Default value: 32
Suggested values: 5, 10, 15, 20, 25, 30, 40, 50
Typical range of values: 1 <= Threshold <= 255 (lin)
Minimum increment: 1
Recommended increment: 5


Example
#include  <iostream.h>
#include  "HalconCpp.h"

int main (int argc, char *argv[])
{
  HImage   image (argv[1]);
  HRegion  empty_region;
  HWindow  win;

  image.Display (win);

  HRegionArray seg = (image >= 100).Connection ();

  seg.Display (win);
  HRegionArray exp = seg.ExpandGray1 (image, empty_region,
                                      "maximal", "image", 32);
  win.SetDraw ("margin");
  win.SetColored (12);
  exp.Display (win);
  win.Click ();

  return (0);
}

Result

::expand_gray always returns the value 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 handling is raised.


Possible Predecessors

::connection, ::regiongrowing, ::pouring, ::class_ndim_norm


Possible Successors

::select_shape


See also

::expand_gray_ref, ::expand_region


Module

Region processing



Copyright © 1996-2002 MVTec Software GmbH