Line detection using tracking approaches with HALCON

A standard task in image processing is the detection of lines. HALCON provides the powerful operator lines_gauss or lines_color for the extraction of lines. These operators are the first choice to detect lines and produce good results for typical applications.

However, if the contrast between the lines which should be detected and the background varies a lot, a single operator call of lines_gauss could fail as shown in the following image: On the bottom of the image, the lines are not detected anymore.

linedetection1

Fig. 1 Result of lines_gauss and problems with varying contrast

Alternative approaches for the extraction of lines are based on tracking algorithms. One of the prerequisites is the availability of a starting point. In some applications the starting points are already given as prior knowledge. If the starting points are still unknown, image processing can be used to extract these points. In the following, we would like to present two possible tracking algorithms, which can be used to extract linear structures suffering from varying contrast between the line and the background.

The first tracking approach is shown in one of the standard examples called track_wires_on_chip.hdev. The basic idea of this approach is to generate a sector of a circle at the starting point. This secular arc is used as region of interest for the detection of possible line segments using the operator lines_gauss. All line segments found in the secular arc are analysed, and the most suitable line is used for tracking the line. This step is repeated iteratively until the end point is reached.

Fig. 2: Tracking approach using iterative lines_gauss in ROI

Fig. 2: Tracking approach using iterative lines_gauss in ROI

Another possibility to avoid using a line detection operator is tracking by means of profile lines that are perpendicular to the lines to be extracted. The profile lines (or alternatively the profile circular arcs) are analysed, and the corresponding point of the line is extracted. The simplest analysis would be selecting the lowest gray value of the profile line, in case the lines are darker than the background. The extraction of the correct line point in the profile can be enhanced by filtering operators or previous knowledge about the line (dark or light lines, maximum curvature, etc.). All iteratively extracted line points can be transformed into a contour, which describes the line.

Fig. 3: Tracking approach using line profiles

Fig. 3: Tracking approach using line profiles

The results of the first tracking approach are depicted in the following figure. As you can see, the approach is suitable for detecting the lines, even though there is a large change in contrast between line and background. Thus, if the quality of a line detection based on a single operator is limited, keep in mind that a tracking approach could significantly improve the results.

Fig. 4: Result of first tracking approach

Fig. 4: Result of first tracking approach