In HALCON region data is represented by a special variant of the runlength encoding – a chord encoding: For every line (chord) of a region its row index (“y coordinate”,“line number”) and the column index (“x coordinate”) of its start and end point is stored. Both the start point and the end point belong to the region.
Chord data must fulfill the following conditions:
If a region is read from the HALCON database of iconic objects, its representation fulfills all the conditions above. When writing a region, condition 2 and 3 need not to be sufficed in all cases, as the Extension Package Interface automatically modifies the data (at cost of computation time).
typedef struct { HIMGCOOR l; /* line number (row) of run */ HIMGCOOR cb; /* column index of beginning of run */ HIMGCOOR ce; /* column index of ending of run */ } Hrun; typedef struct { bool is_compl; /* region is complement */ HITEMCNT num; /* number of runs */ HITEMCNT num_max; /* maximum number of runs */ HRegFeature feature; /* already processed features */ Hrun* rl; /* pointer on array of run lengths */ } Hrlregion;
Figure 4.4: Data type Hrlregion for region encoding.
Figure 4.4 shows the type declaration for chords. In the structure Hrlregion, all chords are stored in an array of the type Hrun, where num is the current and num_max the maximum allowed number of chords (depending on the size of the region specified at its creation, see also section “Memory Management”). The flag is_compl allows an easy transformation of a region in its complement. Operators that work on regions must consider this flag and react according to its value. The structure HRegFeature (see figure 4.5) contains all region shape features extracted so far to avoid repeating a computation. HFeatureFlags encodes, which features already have been extracted. Do not forget to reset these flags if you modify a region.
typedef struct { union { HFeatureFlags single; long all; /* if possible use 64 bits! } def; uint8_t shape; /* SHAPE_* bool is_convex; bool is_filled; bool is_connected4; bool is_connected8; bool is_thin; /* one pixel thin double circularity; double compactness; double contlength; double convexity; double phi; double ra, rb; /* elliptic_axis double ra_, rb_; /* elliptic_shape double anisometry, bulkiness, structure_factor; double m11, m20, m02, ia, ib; double row, col; HIMGCNT area; HIMGCOOR row1, col1, row2, col2; double row_rect, col_rect, phi_rect, length1, length2; double row_circle, col_circle, radius; HIMGCOOR min_chord, max_chord; HIMGCOOR min_chord_gap, max_chord_gap; double rectangularity; } HRegFeature;
Figure 4.5: Data type HRegFeature for region shape features.
Normally, a variable of type Hrlregion is allocated with the procedure HAllocRLTmp or HAllocRLNumTmp, see section “Memory Management”. These routines initialize the data, especially num_max that is needed for tests of overflow. When allocating a variable “by hand”, the programmer must provide a suitable initialization by himself/herself.
Whereas all coordinates within runlength codes are stored as (row,column), linear coordinates are used to address HALCON image matrices. Thus, the macros CB and CE are very helpful, especially when processing gray values (in linear coordinates) along a chord. The programs in figure 6.5 and figure 6.7 illustrate how to use them. Their functionality can be seen in figure 4.6. The first parameter (rl) contains a pointer to the chords as it is used within Hrlregion. index specifies the index of the chord to work on and width contains the image width. CB returns the linear coordinate of the start point and CE that of the end point of the chord.
Names
CB, CE
Synopsis
#include "Halcon.h" HLINCOOR CB(Hrun* rl, HITEMCNT index, HIMGDIM width) HLINCOOR CE(Hrun* rl, HITEMCNT index, HIMGDIM width)
Figure 4.6: Linear coordinates from Hrlregion.