VCLib Documentation  6.12.2

Contour Code

The contour code (CC) is a method for storing one-dimensional contour data of (closed) object contours or edge data (not closed). Instead of storing the x and y coordinates of all contour pixels, the contour code stores a differential 3 bit information, indicating the direction of movement from one pixel to the next in the contour list. With this data structure only the x and y coordinates of the starting point must be given in order to reconstruct the contour.

contour_code.png
CC Address (U32*) CC Meaning
pCC + 0 Count of Contour Pixels.
pCC + 1 CC Status (See Text).
pCC + 2 X Coordinate of Start Pixel.
pCC + 3 Y Coordinate of Start Pixel.
pCC + 4, Byte 0 1. Movement Direction.
pCC + 4, Byte 1 2. Movement Direction.
pCC + 4, Byte 2 3. Movement Direction.
pCC + 4, Byte 3 4. Movement Direction.
pCC + 5, Byte 0 5. Movement Direction.
... ...

The movement directions are encoded by the following Values:

Movement Direction Encoding Value
Up 0
Up Right 1
Right 2
Down Right 3
Down 4
Down Left 5
Left 6
Up Left 7

CC Status

The generation of contour code may terminate due to different stop conditions. If an object contour is followed, the code generation will usually stop when the starting pixel is reached in the same direction (Pixels may be in the contour list more than once, but only once for each direction). The code generation will also stop, if a corner of the image variable is reached or if the space for the contour list is exhausted.

The stop condition is stored in the CC status word in the header of the contour code according to the following table:

Bit Nr. Set Meaning
0 ( 1) Closed Contour (End Pixel = Starting Pixel / Same Direction).
1 ( 2) Contour stops at Left Corner of Image Variable.
2 ( 4) Contour stops at Right Corner of Image Variable.
3 ( 8) Contour stops at Upper Corner of Image Variable.
4 (16) Contour stops at Lower Corner of Image Variable.
5 (32) Space Exhausted (CC Lenght > lng).

Some of the conditions may be true at the same time, for example, contour stops at the left upper corner of the image variable. In this case the individual codes will be added (in example: 2+8 = 10).