J. Vis. Commun. Image R. 38 (2016) 186–194
Contents lists available at ScienceDirect
J. Vis. Commun. Image R. journal homepage: www.elsevier.com/locate/jvci
Unsigned Manhattan chain code q Borut Zˇalik a, Domen Mongus a, Yong-Kui Liu b, Niko Lukacˇ a,⇑ a b
University of Maribor, Faculty of Electrical Engineering and Computer Science, Smetanova 17, SI-2000 Maribor, Slovenia Dalian Nationalities University, Computer Science Department, Dalian 116600, China
a r t i c l e
i n f o
Article history: Received 17 August 2015 Revised 31 January 2016 Accepted 1 March 2016 Available online 2 March 2016 Keywords: Boundary of the rasterised shape Pixel’s neighbourhood of 8-connectivity Chain code properties Monotonic parts Compressibility
a b s t r a c t This paper introduces a new chain code named Unsigned Manhattan Chain Code – UMCC. Although it exploits a pixel’s neighbourhood of 8-connectivity, only two coding symbols are used for navigating through the geometric shape’s boundary pixels. For this, the movements in the x- and y-coordinate direction are separated, whilst the sign of the moving direction is controlled by two flags – one for each coordinate direction. UMCC is insensitive to rotation and mirroring and enables shape magnification. However, the more unique property is the UMCC’s ability to explicitly separate the monotonic parts of the geometric shape. UMCC’s properties have been compared against the properties of other chain codes including the Freeman chain code in eight and four directions, the Vertex Chain Code, and the Three OrThogonal chain code. It has been shown that the UMCC has superior properties in regards to the upto-date chain codes. Ó 2016 Elsevier Inc. All rights reserved.
1. Introduction Efficient representation of rasterised geometric shapes has been of interest since the introduction of the first raster output devices [1]. The more common approach for describing these shapes is by specifying all pixels within the raster regardless of whether they belong to the geometric shapes or not. The pixels’ values are then compressed with a huge palette of developed techniques [2]. An alternative approach for describing bi-level rasterised geometric shapes was proposed by Freeman [3]. He described only the bordered pixels of rasterised shapes by specifying a sequence of instructions (known as a chain code), which navigates through all of the boundary pixels using a pixel’s neighbourhood of 8connectivity. Freeman coded these instructions using an alphabet RðF8Þ ¼ f0; 1; 2; 3; 4; 5; 6; 7g, where F8 stands for the Freeman chain code in eight directions. Fig. 1a shows all possible movements from the current pixel marked dark to the next pixel marked in grey. If a pixel’s 4-connectivity neighbourhood is considered, the Freeman chain code in four directions (F4) is obtained using the alphabet RðF4Þ ¼ f0; 1; 2; 3g (Fig. 1b). Nunes et al. [4] described in 1997 the relative change in the walking direction during a walkabout through the boundary edges of a rasterised shape. Their Differential Chain Code (DCC) contains only three elements, RðDCCÞ ¼ fR; L; Sg, where R, L, and S stand for q
This paper has been recommended for acceptance by C.-H. Yeh.
⇑ Corresponding author.
E-mail address:
[email protected] (N. Lukacˇ). URL: http://gemma.feri.um.si/ (N. Lukacˇ). http://dx.doi.org/10.1016/j.jvcir.2016.03.001 1047-3203/Ó 2016 Elsevier Inc. All rights reserved.
right, left, and straight, respectively. However, DCC is rarely used. In 1999 Bribiesca [5] proposed a chain code with only three symbols in the alphabet, RðVCCÞ ¼ f1; 2; 3g. This code is known as the Vertex Chain Code (VCC) and determines the number of boundary pixels meeting at the considered raster point (see Fig. 2a). Another chain code with three symbols named the Three OrThogonal (3OT) chain code Rð3OTÞ ¼ f0; 1; 2g has been proposed by Sánchez-Cruz and Rodríguez-Diaz [6]. 3OT codes are determined as follows (Fig. 2b): if the current coding direction is the same as the coding direction of its predecessor, the code is 0; if the current coding direction is equal to its first predecessor coding direction, which is different from the direction of its predecessor, the code is 1; otherwise the code is 2. Chain codes are not used just for representing the boundaries of geometric shapes, but also serve for various operations on them as for example: image registration [7], free-form feature representation [8], estimation of physical properties [9], font representations within embedded systems [10], hand-written character recognition [11], medial axis description [12], and others [13–16]. In the shape representation it is desirable that the chain code supports the rotation (at least for a multiplier of 90°), scaling (the enlargement by the multiplier of 2), and mirroring. Traditionally, chain codes are the more frequently used in image processing, where the following properties are desirable [5]:
B. Zˇalik et al. / J. Vis. Commun. Image R. 38 (2016) 186–194
187
0 2
1
3
6
5
7
4
(a) 3 0
2 1
(b) Fig. 1. Freeman chain code in eight (a) and four (b) directions.
2. Unsigned Manhattan chain code
2
1
3
(a) 1
Let G be a rasterised geometric shape and let g i , 0 6 i < n, be the sequence of its boundary pixels, obtained by any contour tracking algorithm [17]. Let g ix and g iy represent pixel’s x- and y-coordinates, respectively. The difference between g i and g iþ1 in regard to their xand y-coordinates are:
x
x di ¼ g iþ1 g ix 2 f1; 0; 1g;
ð1Þ
y
0
2
y g iy 2 f1; 0; 1g: di ¼ g iþ1
x
(b) Fig. 2. Vertex chain code (a) and Three OrThogonal chain code (b).
independence of starting point, independence of rotation and independence of mirroring. However, any additional properties of the chain code may facilitate image processing operations. Such a chain code is proposed in this paper. Beside the properties listed above, this chain code has a unique feature of separating the x- and y-monotonic parts of the geometric shapes’ boundaries. Besides this, the proposed chain code works with only two symbols whilst taking into account the pixels’ 8-connectivity neighbourhood. This new chain code has been named the Unsigned Manhattan Chain Code (UMCC) and is described in Section 2. The properties of UMCC are given in Section 3. The comparison of the UMCC with the other chain codes (F8, F4, VCC, and 3OT) is given in Section 4. Section 5 concludes the paper.
y
Let M ¼ ðM x ; M y Þ, M x ¼ fdi g, M y ¼ fdi g be the sequence of x y pairs ðdi ; di Þ. Providing the position ðpx ; py Þ of the starting pixel, M obviously contains all the information needed for navigating through the boundary pixels of G, i.e. it defines the chain code using the alphabet RðMÞ ¼ RðM x Þ ¼ RðM y Þ ¼ f1; 0; 1g. We consider M as the Manhattan chain code. Let us consider shape G as shown in Fig. 3 with pixels g i shown in grey, whilst the starting pixel is coloured in black. The corresponding Manhattan Chain Code is given in Table 1, where the long runs of the same symbols can be clearly noticed. It becomes obvious that the x- and y-monotonic sections of G transform into a sequence of codes having the same signs (the sign 0 is considered as either positive or negative). This indicates that the number of symbols in the alphabet RðMÞ can be reduced, if a mechanism for alternating the sign of movement could be provided. Such a mechanism is achieved by introducing the sign and the movement context to the chain coding. Namely, when navigating through the boundary pixels g i , the repetition of a single pixel is impossible. This implies that the resulting chain code M cannot contain pair ð0; 0Þ, i.e., g iþ1 – g i ! ð0; 0Þ R M. This unused pair within the movement context can, therefore, be used for indicating that a direction of movement has been changed, i.e., it can switch from the movement to the sign context. Both contexts are explained in the continuation.
B. Zˇalik et al. / J. Vis. Commun. Image R. 38 (2016) 186–194
188
x
y
Fig. 3. Border pixels of rasterised shape. The starting pixel is plotted in black, whilst the direction of the border’s walkabout is indicated by an arrow.
x
y
The movement ðdi ; di Þ, given in the Manhattan Chain Code, is transformed into sign S ¼ ðsix ; siy Þ, ðsix ; siy Þ 2 f1; 1g and an unsigned movement such that: x
x
di ¼ six jdi j;
y
y
di ¼ siy jdi j;
jdi j 2 f0; 1g:
ð2Þ
When coding within the movement context, symbols 1 and 0 are used to indicate whether the movement in the considered coordinate axis has been made or not. The sign S is controlled with x y flag F ¼ ðf i ; f i Þ, where x
y
y y siy ¼ si1 2f i si1 ;
x x six ¼ si1 2f i si1 ;
f i 2 f0; 1g:
ð3Þ
f i ¼ 0 indicates that the sign remains the same, whilst f i ¼ 1 means x y that it has changed. Initially, f 0 ¼ f 0 ¼ 0 and s0x ¼ s0y ¼ 1. Furthermore, it is obvious that any monotonic section of G starts with f i ¼ 1, followed by a sequence of f j ¼ 0, i þ 1 < j < i þ k, where k represents the number of chain codes along the considered monotonic part of G. Because of this, there is no need to code all f i ; it is enough to code only those situations where f i ¼ 1. Therefore, the unsigned movement symbols jdi j and the flags f i can be interlaced within the common stream separated with the symbol pair ð0; 0Þ. This common stream is considered as the Unsigned Manhattan Chain Code (UMCC) and denoted by U ¼ ðU ix ; U iy Þ. The transformation from Manhattan chain code to the Unsigned Manhattan chain code is obtained by the following rules, where ‘’ denotes the concatenation operation: Initialization Rule R1
x
y
U x ¼ U iy ¼ fg, f 0 ¼ f 0 ¼ 0 x fi
¼
y fi
¼0
monotonicity did not change x
U x ¼ U x jdi j y U y ¼ U y jdi j Rule R2
x
y
fi ¼ fi ¼ 1
monotonicity changed in both directions x
Ux ¼ Ux 0 fi y Uy ¼ Uy 0 fi Rule R3
x
y
f i ¼ 1 and f i ¼ 0
monotonicity changed in x-direction x
x
y
f i ¼ 0 and f i ¼ 1
monotonicity changed in y-direction x
3. Properties of the unsigned Manhattan chain code 3.1. Geometric transformation
Ux ¼ Ux 0 fi y y U y ¼ U y 0 f i jdi j Rule R3
Rules 3 and 4 need additional explanation. After the sign context is entered (0-symbol pair is issued), the change of movement in the considered coordinate direction is indicated by 1, whilst symbol 0 means the change of the movement has not occurred. The switch of the sign obviously means that the movement in the considered coordinate direction has been made. However, if the sign has not changed, jdi j is additionally issued for this coordinate direction (see Rules 3 and 4). jdi j ¼ 0 indicates that the coordinate remains unchanged whilst jdi j ¼ 1 increments it. After that the sign context terminates and we automatically return to the movement context, which is represented by Rule 1. However, within the sign context the pair ð0; 0Þ also remains unused. There are different possibilities of how to use it. We have employed it for denoting the repetition of the last used sign combination. It is obvious that the most symbols in UMCC is spent when the sign context is entered. In this case, when using rules R3 and R4, 5 symbols is issued. By using this strategy, one symbol less per one sign context can be spent in some cases. An example of the efficiency of this strategy is considered at the end of this section. Table 2 shows UMCC of shape G from Fig. 3. Symbols in bold are symbols issued within the sign context. The character t is inserted for better readability of the example. In the computer-generated sequences of U x and U y , t does not exist. In the example in Table 2 we have already demonstrated the use of ð0; 0Þ symbols within the sign context. However, a more convincing example is given in Fig. 4, which can be considered as the worse case shape G concerning space requirement, as it does not contain any monotonic part. The obtained UMCC is shown in Table 3, where the benefits of applying the pair ð0; 0Þ within the sign context are demonstrated as an indicator for repeating the last sign symbol combination. Two advantages are obvious: (1) the number of symbols is reduced, and (2) the long stream of 0symbols can be later, if desired, compressed more efficiently.
x
U x ¼ U x 0 f i jdi j y Uy ¼ Uy 0 fi
UMCC enables geometric transformations such as translation, scaling, rotation and mirroring. Translation. Every chain code trivially supports the translation of G by specifying the position ðpx ; py Þ of the first pixel. Scaling. For chain codes the scaling is limited only to magnification. UMCC also follows this principle by duplicating every chain code symbol within the movement context. Let us consider the geometric shape in Fig. 5a and UMCC as given in Table 4. Again, the symbols of the switch mode are written in bold, whilst the duplicated symbols are marked with. The magnified shape is shown in Fig. 5b and the resulting chain code in Table 4.
Table 1 Manhattan chain code of G from Fig. 3. M x: M y:
1 0
1 0
1 1
1 1
1 1
1 1
1 1
1 0
1 0
1 0
0 1
0 1
0 1
1 1
1 1
0 1
0 1
0 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 1
0 1
1 0
1 0
1 0
1 1
1 0
1 1
1 0
1 0
1 1
0 1
0 1
1 0
1 1
M x: M y:
1 0
1 1
1 0
1 0
1 0
1 0
1 1
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
0 1
1 0
1 0
1 1
1 1
1 0
1 1
1 0
1 1
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
M x: M y:
1 0
1 0
1 0
1 0
1 1
1 1 B. Zˇalik et al. / J. Vis. Commun. Image R. 38 (2016) 186–194
Table 2 Unsigned Manhattan chain code of a shape from Fig. 3. U x: U y:
1 0
1 0
1 1
1 1
1 1
0 0
0 1
1 t
1 1
1 0
1 0
1 0
0 0
0 1
0 t
0 1
0 1
0 0
1 0
t 1
0 0
0 0
0 1
0 1
0 1
0 0
1 0
t 0
0 0
0 1
1 t
1 0
1 1
1 0
1 1
1 0
0 0
0 1
1 t
0 0
1 0
t 1
0 1
U x: U y:
0 0
1 0
t 0
1 0
1 0
0 0
0 1
1 t
1 0
1 1
1 0
1 0
0 0
0 0
0 1
0 1
1 0
0 0
0 0
1 1
1 0
1 1
1 0
1 0
1 0
1 0
1 1
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
0 1
0 0
1 0
t 0
1 0
U x: U y:
1 0
1 1
1 1
1 0
1 1
1 0
1 1
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 1
1 1
189
B. Zˇalik et al. / J. Vis. Commun. Image R. 38 (2016) 186–194
190
x
tion. The normalisation is done by circular shifting of the chain code symbols until the resulting sequence forms an integer of minimal magnitude [18]. However, the idea of normalisation cannot be directly applied to UMCC due to the following two reasons:
y
UMCC mixes the chain code and the sign contexts, and UMCC separates the code into coordinates’ directions, i.e. it consists of UMCCx and UMCCy. Despite this, the normalisation of UMCC can be done over the following steps:
Fig. 4. Jagged border of G.
1. Remove (or ignore) all symbols from UMCCx and UMCCy, which were inserted within the sign context. 2. Circular shift left UMCCx until a stream of symbols has the smallest magnitude, and let kx denote the number of shifts. 3. Similarly, circular shift left UMCCy to obtain the smallest magnitude, where ky denotes the number of shifts. 4. Evaluate K ¼ minfkx ; ky g. 5. Shift right UMCCx for kx K (if K ¼ kx there is no shift). 6. Shift right UMCCy for ky K (if K ¼ ky there is no shift). 7. Insert sign symbols at the corresponding places in UMCCx and UMCCy.
Rotation. As already mentioned, during the chain code construction process, s x and s y are initialised to 1. If the initial values of flags s are changed to s x ¼ s y ¼ 0, G is rotated over 180°. Rotation over 90° in the clockwise direction is achieved by exchanging the values in U x and U y . To rotate G over 270°, s x and s y should be initialised to s x ¼ s y ¼ 0 together with exchanging the values of U x and U y . Mirroring. Mirroring is performed similarly to rotation over 180°. If the initial value for s x ¼ 0, mirroring in regards to the y-coordinate axis is obtained. Similarly, by setting s y ¼ 0, mirroring in regards to the x-axis is done.
Let us clarify this procedure with an example using the shape from Fig. 5, the UMMC of which is shown in Table 4. The procedure is shown in Table 5.
As the rotation and mirroring is controlled by the initialisation, the UMCC codes are independent in regard to the orientation and mirroring of G. 3.2. Normalisation of UMCC
3.3. Identifying the monotonic parts of G
In order to perform an unambiguous symbol-by-symbol comparison of two shapes G1 and G2 , the starting positions of both shapes should be the same (e.g. the more left-upper pixels of the shape). If the starting points are not the same, the chain codes of both shapes should be aligned to what is considered as normalisa-
UMMC provides a unique property, which is not implicative for other chain codes. Namely, UMCC splits the shape into its x- or y-monotonic parts. Let us observe the shape in Fig. 6, where the initial pixel is shown in black. The arrows on the top of this pixel indicates the initial movement direction in the positive x- and
Table 3 UMCC for the geometric shape without the monotonic parts (shape in Fig. 4). U x: U y:
1 1
0 0
0 1
1 t
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
U x: U y:
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
1 0
t 1
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
1 0
t 1
0 0
x x
y
y
(a)
(b)
Fig. 5. Scaling: (a) initial shape and (b) magnified shape.
0 0
0 0
0 0
0 0
0 1
1 t
0 0
0 0
0 0
0 0
0 0
0 0
B. Zˇalik et al. / J. Vis. Commun. Image R. 38 (2016) 186–194
191
Table 4 UMCCs of the shape from Fig. 5a and its magnified shape from Fig. 5b. Original shape 1 0 U x: 0 1 U y: Magnified shape 0 U x: 1 1 1 U y: 0 0
0 0 0 1
t 1
1 0
0
1
t
0
0
1
1 1
0 1 0 1
0 1
0 0
0 0
0
0
0
0
1 1
0 1 0 1
0 0
0 1
t 0
1 0
0
1
t
0
0
0
1 0
0 0
0 1
0
0
1
0
1
t
1 t
1 1
1 0
1 0 1 0
1 1
1 1 1 1
1 0
1 0 1 0
0 1 0 1
0 0
0 1
t 0
1 0
0
1
t
0
0
0
1 0
1 1
1 1 1 1
1 0 1 0
1 0
1 1 1 1
1 1
Table 5 Normalisation of UMCC. The input
U x: U y:
1 0
0 1
0 0
1 0
t 1
0 1
0 0
0 0
0 1
0 0
1 0
Remove the sign symbols
U x: U y:
1 0
0 1
0 1
0 1
1 0
1 1
1 0
0 1
1 1
1 0
1 1
Shift left: kx ¼ 1 Shift left: ky ¼ 4 K ¼ minf1; 4g ¼ 1
U x: U y:
0 0
0 1
0 0
1 1
1 1
1 0
0 1
1 0
1 1
1 1
1 1
Shift right: kx K ¼ 0 Shift right: ky K ¼ 3
U x: U y:
0 1
0 1
0 1
1 0
1 1
1 0
0 1
1 1
1 0
1 1
1 0
Return sign symbols
U x: U y:
0 1
0 0
1 0
t 1
0 1
0 0
0 0
0 1
0 0
1 0
t 0
t 0
0 0
0 1
1 t
1 0
1 1
1 0
0 1
0 0
1 0
t 0
1 1
1 0
1 1
0 0
0 1
1 t
1 0
1 1
1 0
0 1
0 0
1 0
t 0
1 1
1 0
1 1
1 0
x
y
Fig. 6. UMCC divides the shape into the monotonic parts. The arrows indicate the directions of the x- or y-coordinate changes.
y-directions. After the first five pixels it can be seen that the direction of movement in the y- direction has changed. This is denoted by the small upward arrow, indicating that the new y-monotonic part arises. In the chain code shown in Table 2 this is manifested with the first ð0; 0Þ pair. The next pair of ð0; 0Þ symbols appear after 5 symbol pairs, i.e. after the next 5 pixels, where the ymonotonicity is changed again (the right most upper arrow in Fig. 6). The next change of monotonicity is in x-direction, which is then immediately changed again. This is indicated with two immediate arrows in the opposite directions in Fig. 6 and with the two following entering into the sign mode in Table 2. The same procedure can be followed until the starting pixel is reached. 4. Comparison of chain code properties Table 6 shows the representations of the shape G from Fig. 3 with F8, F4, VCC, and 3OT chain codes, respectively. The properties of these chain codes are considered in the continuation. F8. The sequence of the equal chain codes represents the straight line segments. We can clearly distinguish amongst the vertical (sequence of codes 2 or 6), the horizontal (sequence of codes 0 or 4), or the diagonal lines with the slope i 45 , i ¼ 1; 3; 5; 7 (sequence of odd codes 1, 3, 5, 7). It is possible to rotate the shape over an angle i 45 , by adding i to each chain
code value using modulus 7, i.e. b ¼ ða þ iÞmodð7Þ, where b is the new code value and a is the old one. The shape G can be scaled by factor k, k ¼ 2i , i 2 N , by inserting each code k times into the chain code sequence. Two shapes G1 and G2 are considered as the same if they have the same number of chain codes (n ¼ jG1 j ¼ jG2 j) and if all chain code pairs are the same, i.e. F8ðG1 ½iÞ ¼ F8ðG2 ½iÞ, 0 6 i < n. If the starting points are not the same, the chain code should be normalised. If the shapes are rotated, their chain codes are different, i.e. F8 is not rotationally invariant. The same is valid for the mirrored shapes. F8 cannot detect the monotonic parts of the shapes. F4. F4 shares the same properties as F8 with one exception, it cannot detect line segments having a slope of 45 by observing only one symbol, and it can perform the rotation only over i 90 . VCC. RðVCCÞ contains three symbols. The sequence of symbol 2 denotes a straight line, either horizontal or vertical, however, we cannot distinguish between them. The sequence of alternating symbols 1 and 3 indicates a diagonal line. The individual symbols 1 and 3 cannot form the sequences. The longest possible sequence is two or, in a special case, four (four symbols 1 describe the shape consisting of a single pixel, whilst four symbols 3 describe a hole having the size of the one pixel). The VCC code is invariant on a rotation and a mirroring [5]. The rotation can be performed by changing the first code. For example, in
B. Zˇalik et al. / J. Vis. Commun. Image R. 38 (2016) 186–194
0 1 1 1 0 0
Table 7 Comparison between chain code properties, where Y means ‘‘yes” and N ‘‘no”.
Detects line Distinguishes between hor. and vert. line Detects diagonal line Invariant on rotation Invariant on mirroring Enables rotations Enables mirroring Enables scaling Detects monotonic parts
F8
F4
VCC
3OT
UMCC
Y Y Y N N Y Y Y N
Y Y N N N Y Y Y N
Y N Y Y Y Y Y N N
Y N Y Y Y N N N N
Y Y Y Y Y Y Y Y Y
1 0 0 2 0 1 2 0 0 2 3OT:
0 1
1 0
1 1
1 1
1 0
1 0
1 0
2 0
1 1
1 1
1 0
0 0
0 0
0 0
2 0
0 0
0 0
0 0
2 0
1 0
1 0
0 0
2 0
0 0
2 1
1 1
0 1
1 1
1 0
0 1
1 1
1 0
0 1
2 1
2 0
1 0
0 0
2 0
0 0
0 0
0 0
2 0
0 0
1 0
1 0
0 0
0 0
2 0
0 0
2 1 3 2 2 3 2 2 1 2 1 3 2 2 1 VCC:
2 3
1 2
3 1
1 3
3 2
1 2
3 2
3 2
1 1
3 3
1 2
2 2
2 2
2 2
1 2
2 2
2 2
2 2
1 2
3 2
1 2
2 2
1 2
2 2
1 3
3 1
2 3
1 1
3 2
2 3
1 1
3 2
2 3
3 1
3 2
1 2
2 2
1 2
2 2
2 2
2 2
1 2
2 2
1 2
3 2
2 2
2 2
3 2
2 2
2 3 2 3 0 2 3 1 0 0 3 0 2 F4:
0 3
1 2
0 2
1 2
0 2
1 2
0 3
0 2
3 2
0 2
3 2
0 2
0 2
0 2
1 2
1 2
1 2
2 2
1 2
1 2
1 0
1 0
3 0
2 3
2 0
3 0
2 3
2 0
3 0
2 3
2 0
2 0
1 0
1 0
0 0
1 0
2 0
2 0
2 0
3 0
2 0
2 0
2 0
2 0
2 0
2 0
1 0
1 3
1 0
4 4 4 3 0 5 0 3 0 2 0 0 7 0 0 0 7 7 7 7 0 1 0 1 6 1 4 0 4 0 4 F8:
Table 6 F8, F4, VCC, and 3OT chain codes for G from Fig. 3.
2 7
2 0
3 0
1 0
2 0
2 0
2 0
4 0
5 0
4 0
4 0
4 0
1 0
2 0
4 0
4 7
4
5
4
5
4
4
3
2
2
4
5
4
5
4
4
4
5
4
4
4
4
4
4
4
192
Table 6 the first code is 2. If it is changed to 1, the shape is rotated over 90°. Similarly, if it is changed to 3, the rotation for 90° is obtained. The mirroring is obtained by turning the VCC chain code sequence. However, VCC does not enable scaling. The monotonic shape’s parts cannot be directly distinguished. 3OT. Similarly as VCC, the straight lines are clearly detectable as a sequence of symbols 0, but between them cannot be distinguished. In contrary to VCC, the diagonal lines of the slope 45 are easily detectable as a sequence of symbols 1. Symbol 2 cannot appear in the sequence (except in the special case describing a hole of the size one pixel). 3OT is invariant on the rotation and the mirroring. Although, 3OT is invariant to rotation, the rotation cannot be performed on the code itself. 3OT either does not support scaling, and mirroring, neither can it identify the monotonic shape’s parts. UMCC. The horizontal and vertical lines are easily detected. In this case U x and U y contains a sequence of the same symbols (either 0 or 1). We can easily distinguish between the vertical and the horizontal line. The diagonal line is characterised by the sequence of symbols 1 in both coordinate directions. In the previous Section we showed how to rotate, mirror, and scale the geometric shape. The comparison of chain codes’ properties is given in Table 7. 4.1. Memory requirements Although the chain codes already act as a compact representation of rasterised shapes, they can still be further compressed. Over recent years many chain code compression methods have been developed, however, for the purpose of this paper just the more characteristic are briefly mentioned. Liu et al. [19] proposed three methods for compressing VCC; namely E_VCC, V_VCC, and C_VCC. Whilst the first two explore the redundancy in the VCC itself, the latest one uses Huffman coding for the more frequent combinations of VCC codes. Sánchez-Cruz et al. [20] introduced additional symbols 3, 4, and 5 to encode frequent combinations of 3OT symbols 0 and 1 within their M_3OT chain code. Instead of static Huffman coding the arithmetic coding on 3OT is suggested in [21]. Zˇalik and Lukacˇ [22] applied Move-To-Front transform to reduce the information entropy, followed by the Adaptive RLE. To unify the compressions of the chain codes, a Universal Chain Code Compression (UCCC) algorithm has recently been demonstrated [23]. Nunes et al. [4] and Liu et al. [24] proposed near-lossless approaches, where both used Huffman coding. In the continuation, UMCC is compared against the memory requirement with all popular chain codes including F8, F4, VCC, and 3OT. For testing, the benchmark shapes shown in Fig. 7 were used.1 The number of chain code symbols needed to describe these shapes are given in Table 8. As VCC and 3OT differ for only 1 the shape are obtained from Chain Codes Datasets Repository located at ‘‘http:// gemma.feri.um.si/chaincodes”; version 2.0.
B. Zˇalik et al. / J. Vis. Commun. Image R. 38 (2016) 186–194
193
Fig. 7. Shapes used for testing [23].
Table 10 The number of bits spent by chain codes when BAC is applied.
Table 8 The number of chain code symbols needed to describe the shapes. Shape Bird Butterfly Circle Fire Horse Plane Shuttle Spider Square Star Thunder Tiger
F8 1733 1379 756 2137 3953 1492 969 4109 1092 1024 1440 3835
F4 2361 2008 1068 2908 4310 2260 1232 5992 1092 1448 2474 4250
VCC and 3OT 2377 2013 1073 2913 4315 2265 1237 5997 1097 1452 2481 4255
UMCC
Shape
F8
F4
VCC
3OT
UMCC
3649 2899 1521 4313 8101 3023 1971 8425 2190 2069 2913 7805
Bird Butterfly Circle Fire Horse Plane Shuttle Spider Square Star Thunder Tiger
4253 3739 2003 5259 8049 3238 2143 10,266 1347 2270 2789 7796
3886 3457 1781 4536 5885 3120 1731 9794 743 1900 2687 5794
2953 2469 1346 3446 3349 2483 1442 6959 111 1535 2199 3771
2580 2151 1170 2925 2778 2059 1244 5978 105 1730 1960 3354
2633 2153 874 2279 5827 1502 1195 4959 208 880 1377 5723
Table 9 The number of bits spent by various chain codes. Shape
F8
F4
VCC and 3OT
UMCC
Bird Butterfly Circle Fire Horse Plane Shuttle Spider Square Star Thunder Tiger
5199 4137 2268 6411 11,859 4476 2907 12,327 3276 3072 4320 11,505
4744 4016 2136 5816 8620 4520 2464 11,984 2184 2896 4952 8500
4754 4026 2146 5826 8630 4530 2474 11,994 2194 2904 4962 8510
3649 2899 1521 4313 8101 3023 1971 8425 2190 2069 2913 7805
UMCC has only two symbols, which can already be considered as a bit. Table 9 shows the number of bits needed for representing geometric shapes from Fig. 7 with all the chain codes. As can be seen UMCC spends at least bits in all tested cases except one (shape square represented by F4 are slightly better). In order to further reduce the number of bits, one of the methods for information entropy reduction can be applied. As in our case the stream of bits is obtained, the more natural selection is a binary arithmetic coder – BAC [25]. We have applied the adaptive binary arithmetic coder FPAQ0f.2 The bits from Table 9 are coded and the results of compression are shown in Table 10. The best results are given in bold. As seen, 3OT and UMCC give the best results in all cases. 5. Conclusion
one symbol, they are given in the same column. From Table 8 it can be seen that UMCC requires considerably more codes that other codes. The smallest number of chain codes is required by F8. However, the situation drastically changes when the number of bits needed for storing the chain codes is considered. F8’s alphabet consists of 8 symbols and each of them should be coded with 3 bits. F4’s alphabet contains 4 symbols, where each of them is coded with two bits. VCC and 3OT are defined by three symbols and therefore, two symbols are used for their representation, too.
This paper introduced a new chain code named Unsigned Manhattan Chain code (UMCC). It considers the movement through the shape’s boundary pixels by separating the x- and y-coordinate directions. UMCC switches between the movement and the sign context and in this way, only 2 symbols {0, 1} are needed. In the paper we have shown that the geometric shapes being represented by UMCC can be rotated, mirrored, magnified, and that the 2
https://cs.fit.edu/mmahoney/compression/#fpaq0.
194
B. Zˇalik et al. / J. Vis. Commun. Image R. 38 (2016) 186–194
obtained chain code can be normalised. By observing the changes of symbols in the sign context, the monotonic parts of the geometric shape in the x- and y-directions can be directly obtained. UMCC has been compared with other chain codes including Freeman chain code in eight (F8) and four (F4) directions, Vertex Chain Code (VCC), and Three OrThogonal chain code (3OT) according to the properties and the compressibility. It has been shown that the UMCC has the superior properties and that it spend at least bits in regards to the other chain codes. Acknowledgments This work was supported by the Slovenian Research Agency under Grants J2-5479, J2-6764, 1000-13-0552 and Slovenian– Chinese bilateral project BI-CN/14-15-007. References [1] A.M. Noll, Scanned-display computer graphics, Commun. ACM 14 (3) (1971) 143–150. [2] D. Salomon, G. Motta, Handook of Data Compression, fifth ed., Springer, 2010. [3] H. Freeman, On the encoding of arbitrary geometric configurations, IRE Trans. Electron. Comp. EC10 (1961) 260–268. [4] P. Nunes, F. Pereira, F. Marqués, Multi-grid chain coding of binary shapes, in: ICIP’97 Proceedings of the 1997 International Conference on Image Processing, vol. 3, DC, USA, 1997, pp. 114–117. [5] E. Bribiesca, A new chain code, Pattern Recog. 32 (2) (1999) 235–251. [6] H. Sánchez-Cruz, R.M. Rodríguez-Dagnino, Compressing bi-level images by means of a 3-bit chain code, SPIE Optical Eng. 44 (9) (2005) 1–8. [7] X. Dai, S. Khorram, A feature-based image registration algorithm using improved chain-code representation combined with invariant moments, IEEE Trans. Geosci. Rem. Sens. 37 (5) (1999) 2351–2362. [8] R.K. Gupta, B. Gurumoorthy, Automatic extraction of free-form surface features (ffsfs), Comp. Aided Des. 44 (2) (2012) 99–112. [9] N. Ge, G.-Q. Wu, H.-P. Li, Z. Wang, C.-Y. Bao, Evaluation of the two-dimensional temperature field and instability of a dual-jet DC arc plasma based on the image chain coding technique, IEEE Trans. Plasma Sci. 39 (11) (2011) 2885– 2994.
[10] T. Globacˇnik, B. Zˇalik, An efficient raster font compression for embedded systems, Pattern Recog. 43 (12) (2010) 4137–4147. [11] J. Jain, S.K. Sahoo, S.M. Prasanna, G.S. Reddy, Modified chain code histogram feature for handwritten character recognition, in: Advances in Computer Science and Information Technology, Networks and Communications, Springer, Berlin Heidelberg, 2012, pp. 611–619. [12] T. Pavlidis, Algorithms for shape analysis of contours and waveforms, IEEE Trans. Pattern Anal. Mach. Intell. 2 (4) (1980) 301–312. [13] K. Li, X.W. Gao, W.B. Yang, Y.L. Dai, Multiple fault diagnosis of down-hole conditions of sucker-rod pumping wells based on Freeman chain code and DCA, Petrol. Sci. 10 (3) (2013) 347–360. [14] M. Ren, H.A. Karimi, A chain-code-based map matching algorithm for wheelchair navigation, Trans. GIS 13 (2) (2009) 197–214. [15] H. Sun, J. Yang, M. Ren, A fast watershed algorithm based on chain code and its application in image segmentation, Pattern Recog. Lett. 26 (9) (2005) 1266– 1274. [16] C. Wang, J. Zhou, P. Kou, Z. Luo, Y. Zhang, Identification of shaft orbit for hydraulic generator unit using chain code and probability neural network, Appl. Soft Comput. 12 (1) (2012) 423–429. [17] A. Chen, T. Wittman, A.G. Tartakovsky, A.L. Bertozzi, Efficient boundary tracking through sampling, Appl. Math. Res. Exp. 2011 (2) (2011) 182–214. [18] D.H. Ballard, C.M. Brown, Computer Vision, Prentice Hall, Englewood Cliffs, NJ, 1982. [19] Y.K. Liu, W. Wei, P.-J. Wang, B. Zˇalik, Compressed vertex chain codes, Pattern Recog. 40 (11) (2007) 2908–2913. [20] H. Sánchez-Cruz, M. López-Cruces, H. Puga, A proposal modification of the 3OT chain code, in: CGIM’08 Proceedings of the Computer Graphics and Imaging, Innsbruck, Austria, 2008, pp. 6–11. [21] H. Sánchez-Cruz, M.A. Rodríguez-Diaz, Coding long contour shapes of binary objects, in: CIARP’09 Proceedings of the 14th Iberoamerican Conference on Pattern Recognition, Berlin, Heidelberg, 2009, pp. 45–52. [22] B. Zˇalik, N. Lukacˇ, Chain code lossless compression using move-to-front transform and adaptive run-length encoding, Signal Process.: Image Commun. 29 (1) (2014) 96–106. [23] B. Zˇalik, D. Mongus, N. Lukacˇ, A universal chain-code compression method, Image Vis. Comput. (2015). [24] Y.-K. Liu, B. Zˇalik, P.-J. Wang, D. Podgorelec, Directional difference chain codes with quasi-lossless compression and run-length encoding, Signal Process.: Image Commun. 27 (9) (2012) 973–984. [25] G.G. Langdon Jr., J. Rissanen, A simple general binary source code, IEEE Trans. Inf. Theory 28 (5) (1982) 800–803.