ClassesClassesClassesClasses | | | | Operators

char_thresholdchar_thresholdCharThresholdchar_thresholdCharThresholdCharThreshold (Operator)

Name

char_thresholdchar_thresholdCharThresholdchar_thresholdCharThresholdCharThreshold — Perform a threshold segmentation for extracting characters.

Signature

char_threshold(Image, HistoRegion : Characters : Sigma, Percent : Threshold)

Herror char_threshold(const Hobject Image, const Hobject HistoRegion, Hobject* Characters, double Sigma, double Percent, Hlong* Threshold)

Herror T_char_threshold(const Hobject Image, const Hobject HistoRegion, Hobject* Characters, const Htuple Sigma, const Htuple Percent, Htuple* Threshold)

Herror char_threshold(Hobject Image, Hobject HistoRegion, Hobject* Characters, const HTuple& Sigma, const HTuple& Percent, Hlong* 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, Hlong* Threshold) const

HRegionArray HImageArray::CharThreshold(const HRegion& HistoRegion, const HTuple& Sigma, const HTuple& Percent, HTuple* Threshold) const

void CharThreshold(const HObject& Image, const HObject& HistoRegion, HObject* Characters, const HTuple& Sigma, const HTuple& Percent, HTuple* Threshold)

HRegion HImage::CharThreshold(const HRegion& HistoRegion, double Sigma, const HTuple& Percent, HTuple* Threshold) const

HRegion HImage::CharThreshold(const HRegion& HistoRegion, double Sigma, double Percent, Hlong* Threshold) const

void HOperatorSetX.CharThreshold(
[in] IHUntypedObjectX* Image, [in] IHUntypedObjectX* HistoRegion, [out] IHUntypedObjectX*Characters, [in] VARIANT Sigma, [in] VARIANT Percent, [out] VARIANT* Threshold)

IHRegionX* HImageX.CharThreshold(
[in] IHRegionX* HistoRegion, [in] double Sigma, [in] VARIANT Percent, [out] VARIANT* Threshold)

static void HOperatorSet.CharThreshold(HObject image, HObject histoRegion, out HObject characters, HTuple sigma, HTuple percent, out HTuple threshold)

HRegion HImage.CharThreshold(HRegion histoRegion, double sigma, HTuple percent, out HTuple threshold)

HRegion HImage.CharThreshold(HRegion histoRegion, double sigma, double percent, out int threshold)

Description

The main application of char_thresholdchar_thresholdCharThresholdchar_thresholdCharThresholdCharThreshold 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 ImageImageImageImageImageimage is computed for the points in the region HistoRegionHistoRegionHistoRegionHistoRegionHistoRegionhistoRegion{}. To eliminate noise, the histogram is smoothed with the given SigmaSigmaSigmaSigmaSigmasigma (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 binary_thresholdbinary_thresholdBinaryThresholdbinary_thresholdBinaryThresholdBinaryThreshold (with 'Method'"Method""Method""Method""Method""Method"='smooth_histo'"smooth_histo""smooth_histo""smooth_histo""smooth_histo""smooth_histo"), 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 - PercentPercentPercentPercentPercentpercent)

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

In comparison to binary_thresholdbinary_thresholdBinaryThresholdbinary_thresholdBinaryThresholdBinaryThreshold, 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.

Parallelization

Parameters

ImageImageImageImageImageimage (input_object)  singlechannelimage(-array) objectHImageHImageHImageHImageXHobject (byte)

Input image.

HistoRegionHistoRegionHistoRegionHistoRegionHistoRegionhistoRegion (input_object)  region objectHRegionHRegionHRegionHRegionXHobject

Region in which the histogram is computed.

CharactersCharactersCharactersCharactersCharacterscharacters (output_object)  region(-array) objectHRegionHRegionHRegionHRegionXHobject *

Dark regions (characters).

SigmaSigmaSigmaSigmaSigmasigma (input_control)  number HTupleHTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double) (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 Sigma Sigma Sigma Sigma sigma ≤ 50.0 (lin)

Minimum increment: 0.01

Recommended increment: 0.2

PercentPercentPercentPercentPercentpercent (input_control)  number HTupleHTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (double / Hlong) (double / Hlong) (double / Hlong)

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 Percent Percent Percent Percent percent ≤ 100.0 (lin)

Minimum increment: 0.1

Recommended increment: 0.5

ThresholdThresholdThresholdThresholdThresholdthreshold (output_control)  integer(-array) HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Calculated threshold.

Example (HDevelop)

read_image (Image, 'letters')
char_threshold (Image, Image, Seg, 0.0, 5.0, Threshold)
connection (Seg, Connected)

Example (C)

read_image(&Image,"letters");
char_threshold(Image,Image,&Seg,0.0,5.0,&Threshold);
connection(Seg,&Connected);
set_colored(WindowHandle,12);
set_shape(WindowHandle,"rectangle1");
disp_region(Connected,WindowHandle);

Example (HDevelop)

read_image (Image, 'letters')
char_threshold (Image, Image, Seg, 0.0, 5.0, Threshold)
connection (Seg, Connected)

Example (C++ (HALCON 5.0-10.0))

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

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

  HImage       image(argv[1]);
  HWindow      w;
  HTuple       threshold;

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

  image.Display(w);

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

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

  return 0;
}

Example (HDevelop)

read_image (Image, 'letters')
char_threshold (Image, Image, Seg, 0.0, 5.0, Threshold)
connection (Seg, Connected)

Example (HDevelop)

read_image (Image, 'letters')
char_threshold (Image, Image, Seg, 0.0, 5.0, Threshold)
connection (Seg, Connected)

Possible Predecessors

anisotropic_diffusionanisotropic_diffusionAnisotropicDiffusionanisotropic_diffusionAnisotropicDiffusionAnisotropicDiffusion, median_imagemedian_imageMedianImagemedian_imageMedianImageMedianImage, illuminateilluminateIlluminateilluminateIlluminateIlluminate

Possible Successors

connectionconnectionConnectionconnectionConnectionConnection, select_shapeselect_shapeSelectShapeselect_shapeSelectShapeSelectShape, select_grayselect_graySelectGrayselect_graySelectGraySelectGray

Alternatives

binary_thresholdbinary_thresholdBinaryThresholdbinary_thresholdBinaryThresholdBinaryThreshold, auto_thresholdauto_thresholdAutoThresholdauto_thresholdAutoThresholdAutoThreshold, gray_histogray_histoGrayHistogray_histoGrayHistoGrayHisto, smooth_funct_1d_gausssmooth_funct_1d_gaussSmoothFunct1dGausssmooth_funct_1d_gaussSmoothFunct1dGaussSmoothFunct1dGauss, thresholdthresholdThresholdthresholdThresholdThreshold

Module

Foundation


ClassesClassesClassesClasses | | | | Operators