Skip to content

Subpixel-precise edge extraction🔗

HALCON provides different ways to extract edges. There are the pixel-precise approaches of applying an edge filter or a deep-learning-based semantic segmentation model. In addition, there are one-step operators that return subpixel-precise XLD contours. Besides this, not only edges but also lines can be extracted. This approach can also be applied to color images.

The advantage of this approach is its ease of use, because only a single operator call is needed. Furthermore, the accuracy and stability of the found contours is extremely high. Finally, HALCON offers a wide set of operators for the post-processing of the extracted contours, which includes, for example, contour segmentation and fitting of circles, ellipses, and lines.

Extracting edges or lines🔗

HALCON offers various operators for the subpixel-accurate extraction of contours. The standard operator is based on the first derivative. It takes the image as input and returns the XLD contours. When using the second derivatives, first a Laplace operator must be executed before the contours along the zero crossings can be extracted. Besides the gray-value-based methods, HALCON provides the operators for the extraction of color edges.

Besides the extraction of edges, HALCON provides operators for the extraction of lines. In other systems lines are also called ridges. In contrast to edges, a line consists of two gray value transitions. Thus, a line can be considered as two parallel edges.

Extracting edges🔗

The most commonly used operator for subpixel-precise edge contour extraction is edges_sub_pix. You can select various filter methods by specifying the corresponding name with the parameter Filter. For standard applications, common values are, for example, 'canny' (based on a Gaussian convolution) or 'lanser2'. The advantage of 'lanser2' is the recursive implementation which has no increase in execution time when using a large smoothing. As a fast version the parameter value 'sobel_fast' can be used, which is recommended as long as the image is not noisy or blurred.

The operator zero_crossing_sub_pix can be used in combination with a filter like derivate_gauss with parameter value 'laplace'. The Laplace operator is mainly applied in the medical area.

To extract edges in multi-channel images, for example, in a color image, HALCON provides the operator edges_color_sub_pix. Similar to edges_sub_pix, the parameter value 'sobel_fast' is recommended for a fast edge extraction as long as the image is not noisy or blurred.

Extracting lines🔗

The most commonly used operator for line extraction is lines_gauss. Compared to lines_facet it is more robust and provides more flexibility. The width of lines that should be extracted is specified by the parameter Sigma: The wider the line, the larger the value must be chosen. For very wide lines we recommend to zoom down the image (zoom_image_factor) in order to reduce the overall execution time.

Like for edges, HALCON provides line extraction also for multi-channel images. The corresponding operator is lines_color.

Determine contour attributes🔗

The edge and line extraction operators not only provide the XLD contours but also so-called attributes. Attributes are numerical values; they are associated either with each control point of the contour (called contour attribute) or with each contour as a whole (global contour attribute). The operators get_contour_attrib_xld and get_contour_global_attrib_xld enable you to access these values by specifying the attribute name.

The attribute values are returned as tuples of numbers. Typical attributes for edges are, for example, the edge amplitude and direction. For lines a typical attribute is the line width. The available attributes can be queried for a given contour with query_contour_attribs_xld and query_contour_global_attribs_xld.

Typically, the task is not finished by just extracting the contours and accessing the attributes. HALCON provides further processing like contour segmentation, feature extraction, or approximation.

Programming examples🔗

Some example applications are shown in the following programs:

  • Measuring the diameter of drilled holes:
    %HALCONEXAMPLES%/solution_guide/basics/rim_simple.hdev

  • Extracting blood vessels in X-ray images:
    %HALCONEXAMPLES%/hdevelop/Filters/Lines/lines_gauss.hdev