Herror ::char_threshold (
    Hobject Image,
    Hobject HistoRegion,
    Hobject *Characters,
    const HTuple &Sigma,
    const HTuple &Percent,
    long *Threshold
)
Herror ::char_threshold (
    Hobject Image,
    Hobject HistoRegion,
    Hobject *Characters,
    const HTuple &Sigma,
    const HTuple &Percent,
    HTuple *Threshold
)
HRegion HImage::CharThreshold (
    const HRegion &HistoRegion,
    const HTuple &Sigma,
    const HTuple &Percent,
    long *Threshold
) const
HRegionArray HImageArray::CharThreshold (
    const HRegion &HistoRegion,
    const HTuple &Sigma,
    const HTuple &Percent,
    HTuple *Threshold
) const

Perform a threshold segmentation for extracting characters.

The main application of ::char_threshold is to segment single-channel images of dark characters on bright paper. The operator works as follows: First, a histogram of the gray values in the image Image is computed for the points in the region HistoRegion{}. To eliminate noise, the histogram is smoothed with the given Sigma (Gaussian smoothing). In the histogram, the background (white paper) corresponds to a large peak at high gray values, while the characters form a small peak at low gray values. In contrast to the operator ::bin_threshold, which locates the minimum between the two peaks, here the threshold for the segmentation is determined in relation to the maximum of the histogram, i.e., the background, with the following condition:


       histogram[threshold] * 100.0 < histogram[maximum] * (100.0 - Percent)

For example, if you choose Percent = 95 the operator locates the gray value whose frequency is at most 5 percent of the maximum frequency. Because ::char_threshold assumes that the characters are darker than the background, the threshold is searched for ``to the left'' of the maximum.

In comparison to ::bin_threshold, this operator should be used if there is no clear minimum between the histogram peaks corresponding to the characters and the background, respectively, or if there is no peak corresponding to the characters at all. This may happen, e.g., if the image contains only few characters or in the case of a non-uniform illumination.


Parameters

Image (input_object)
image(-array) -> Hobject: HImage(Array) ( byte )
Image to be segmented.

HistoRegion (input_object)
region -> Hobject: HRegion
Region in which the histogram is computed.

Characters (output_object)
region(-array) -> Hobject * : HRegion(Array)
Dark regions (characters).

Sigma (input_control)
number -> HTuple.double
Sigma for the Gaussian smoothing of the histogram.
Default value: 2.0
Suggested values: 0.0, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0
Typical range of values: 0.0 <= Sigma <= 50.0 (lin)
Minimum increment: 0.01
Recommended increment: 0.2

Percent (input_control)
number -> HTuple.double / long
Percentage for the gray value difference.
Default value: 95
Suggested values: 90, 92, 95, 96, 97, 98, 99, 99.5, 100
Typical range of values: 0.0 <= Percent <= 100.0 (lin)
Minimum increment: 0.1
Recommended increment: 0.5

Threshold (output_control)
integer(-array) -> (HTuple.) long *
Calculated threshold.


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

int main (int argc, char *argv[])
{
  if (argc != 2)
  {
    cout << "Usage : " << argv[0] << " 'image' " << endl;
    return (-1);
  }

  HImage       image (argv[1]),
               med;
  HWindow      w;

  w.SetDraw ("margin");
  w.SetShape ("rectangle1");
  w.SetColored (12);

  image.Display (w);

  HRegionArray reg = image.CharThreshold(0,5,&Threshold);
  HRegionArray con = reg.Connection ();

  cout << "Display image after CharThreshold segmentation " << endl;
  con.Display (w);
  w.Click ();

  return (0);
}

Possible Predecessors

::anisotrope_diff, ::median_image, ::illuminate


Possible Successors

::connection, ::select_shape, ::select_gray


Alternatives

::bin_threshold, ::auto_threshold, ::gray_histo, ::smooth_funct_1d_gauss, ::threshold


Module

Region processing



Copyright © 1996-2002 MVTec Software GmbH