A universal chain code compression method

A universal chain code compression method

J. Vis. Commun. Image R. 29 (2015) 8–15 Contents lists available at ScienceDirect J. Vis. Commun. Image R. journal homepage: www.elsevier.com/locate...

680KB Sizes 1 Downloads 154 Views

J. Vis. Commun. Image R. 29 (2015) 8–15

Contents lists available at ScienceDirect

J. Vis. Commun. Image R. journal homepage: www.elsevier.com/locate/jvci

A universal chain code compression method q Borut Zˇalik ⇑, Domen Mongus, Niko Lukacˇ University of Maribor, Faculty of Electrical Engineering and Computer Science, Smetanova 17, SI-2000 Maribor, Slovenia

a r t i c l e

i n f o

Article history: Received 12 September 2014 Accepted 18 January 2015 Available online 4 February 2015 Keywords: Image processing 2D shapes Contours Chain codes Compression Run length encoding Dictionary coding Data modelling

a b s t r a c t This paper introduces a new approach for lossless chain code compression. Firstly, the chain codes are converted into the binary stream, independent on the input chain code. Then, the compression is done using three modes: RLE0 ; LZ770 and COPY. RLE0 compresses the runs of the 0-bits, LZ770 is a simplified version of LZ77 and handles the repetitions within the bit stream, whilst COPY is an escape mode used, when the other two methods are unsuccessful. This method has been tested on the Freeman chain code in eight and four directions, the Vertex chain code, the Three OrThogonal chain code, and the Normalized angle difference chain code. The experiments confirmed better compression ratios on various benchmark datasets in comparison to the state-of-the-art lossless chain code compression methods. Ó 2015 Elsevier Inc. All rights reserved.

1. Introduction Chain codes are popular representation methods for rasterised shapes within various scientific and engineering disciplines [1–9]. The chain code can be regarded as a sequence of commands, which control the movement of a virtual walker throughout all the boundary pixels of a shape. The most intuitive chain code was proposed by Freeman back in 1961 [10] using pixels’ 8-connectivity (Fig. 1a) known as Freeman 8-directional chain code (i.e. F8). The movement through the boundary pixels is encoded with an alphabet RðF8Þ ¼ f0; 1; 2; 3; 4; 5; 6; 7g, where each element r 2 R represents a 45  r angle from the positive direction of the x coordinate axis. Freeman also determined that the boundaries of digitalised shapes can be described by the pixels’ 4-connectivity (Freeman 4-directional chain code (F4)) by encoding 90  r angle using the shorter alphabet RðF4Þ ¼ f0; 1; 2; 3g (see Fig. 1b). Nunes et al. [11] encoded the boundary edges of the shape instead of the pixels and therefore the walking direction should be specified. They proposed differential chain code (DCC), the first chain code with only three elements. Namely, the DCC alphabet RðDCCÞ ¼ fR; L; Sg, where R stands for right, L for left, and S for straight. In 1999 Bribiesca discovered a new, nowadays very popular chain code, named the vertex chain code (VCC) [12]. VCC determines the number of boundary pixels in the raster junctions (see

q

This paper has been recommended for acceptance by Prof. M.T. Sun.

⇑ Corresponding author. Fax: +386 2 220 7272. E-mail address: [email protected] (B. Zˇalik). URL: http://gemma.uni-mb.si (B. Zˇalik).

http://dx.doi.org/10.1016/j.jvcir.2015.01.013 1047-3203/Ó 2015 Elsevier Inc. All rights reserved.

Fig. 1b) and also has an alphabet with only three codes RðVCCÞ ¼ f1; 2; 3g. The Three OrThogonal (3OT) chain code was introduced in 2005 [13]. Its codes are determined as follows:  if the current coding direction is the same as the coding direction of its predecessor, r ¼ 0;  if the current coding direction is equal to its first predecessor whose coding direction is different than the direction of its predecesor, r ¼ 1;  r ¼ 2 otherwise. The 3OT alphabet therefore consists of three symbols

Rð3OTÞ ¼ f0; 1; 2g (see Fig. 2b). Chain codes are used for describing geometrical shapes, which may take a lot of memory storage on today’s high-resolution devices, hence various domain-specific chain code compression methods have been developed. Sánchez-Cruz and Rodríguez-Diaz [14] showed that chain code based compression of bi-level images can achieve even better results than JBIG [15]. This paper is structured as follows: the next section provides a brief overview of existing chain code compression methods. Section 3 introduces a new universal lossless chain code compression approach. The efficiency of the proposed approach is demonstrated in Section 4 using benchmark shapes. Section 5 concludes the paper. 2. Related work on chain code compression The pioneering work in the chain code compression has been done by Nunes et al., who used Huffman codes on DCC [11]. Their

B. Zˇalik et al. / J. Vis. Commun. Image R. 29 (2015) 8–15

compression was quasi-lossless (i.e. near-lossless), as some of the original data were lost at the expense of better compression. Another Huffman-based compression was proposed by Liu and Zˇalik [16] on their directional difference chain code (DDCC). DDCC encodes eight angular differences of F8 (a modification of DDCC – a Normalised angle difference was used in our test and explained in Section 3). Liu et al. later [17] introduced three methods for VCC compressing, namely: extended VCC (E_VCC), variable VCC (V_VCC), and compressed VCC (C_VCC). The first method encodes symbol combinations f1; 3g (or f3; 1g) as a single code employing the unused bit combination of three VCC code, V_VCC encodes symbol 2 with one bit, and the remaining two symbols with two bits, whilst C_VCC provides even further compression by utilising Huffman codes for the more frequent combinations of VCC symbols. Sánchez-Cruz et al. [18] introduced a modified 3OT (M_3OT) chain code, which achieves higher compression ratios by introducing symbols 3; 4, and 5 in order to encode frequent combinations of 3OT chain code symbols 0 and 1. Soon after they improved the 3OT and DDCC chain codes [14], where arithmetic coding was used instead of statically determined Huffman codes. Sánchez-Cruz [19] also proposed a newer compression method for F8 by finding

4

4

4

4

9

repetitive substrings within the chain code. Liu et al. [20] have recently proposed another quasi-lossless chain code compression method, which replaces less frequent angular differences (i.e. 135 and 180 ) in DDCC with pairs of more frequent ones. They have also introduced a run-length encoding (RLE) scheme in order to further compress repetitive runs of 0° angular differences. Recently, Zˇalik and Lukacˇ [21] developed a new lossless chain code compression that does not rely on statistical assumptions (i.e. Huffman coding tables), but rather use a move-to-front transform (MTFT) to reduce the information entropy and then encode the transformed symbols with adaptive RLE (ARLE). To date, this method provided the most efficient compression of VCC, 3OT, and normalised angle difference (NAD). Chain codes can also be used for the compression of 3D voxelised shapes, as recently demonstrated by Lemus et al. [22].

3. The proposed lossless compression method The algorithms for chain code compression developed to date and briefly summarised in Section 2, have been dedicated to spe2

4

2

2

2

2

1

2 6

3

2 0

0

3

1

7

1 0 2

5

1

1 3 4

4

2

2

6

3

0

3 0

1 2

5

3 1

2

5 5

1

0

0

0

0

0

1 2

3

2

2

1

3

0

0

0

0

0

0

0

(a)

0

0

0

2

0

(b) Fig. 1. Freeman chain codes: (a) F8 and (b) F4.

1

2

2

2

2

2

1 0

0

0

0

2

2

2 2 1

2

2

2

3

1

3 3

1

1

2

1

1

0

3

3

2

1 2

1

1

1

1

3 1

1

0 1

3

1

0 1

3 3

1

0

0

2

1

2

1

1 1

0

1

2

0

1

2

2

1

0 2

2

2

2

2

0

0

1

(a)

(b) Fig. 2. Chain codes: (a) VCC and (b) 3OT.

0

0

B. Zˇalik et al. / J. Vis. Commun. Image R. 29 (2015) 8–15

10

F8 F4

F8, 3OT, NAD

RLE0

VCC 3OT

data modeling & binarization

0100110..

-coding

NAD

forming output data stream

LZ77 0

F4, VCC

:::

UCCC

COPY

Fig. 3. Block diagramme of a universal chain code compressor.

cific chain codes. Adaptation to other chain codes is either impossible or requires considerable changes in the methodology and implementation. In this paper an Universal Chain Code Compressor (UCCC) is proposed. Its block scheme is shown in Fig. 3. Before UCCC, the chain code dependent data modelling is performed. After that d–coding may be applied. The core of the UCCC are three modes denoted as RLE0 ; LZ770 , and COPY. Finally, the output bitstream is formed. The steps of UCCC are considered in more details in the next subsections.

is therefore coded with one bit. The sequences of 90 or 90 turns are equally probable, but, unfortunately, one should encode them with two and three bits, respectively. However, runs of equal bits can be obtained by careful selection of the codes. This also works in the case of alternating 90 codes (in this case, the runs of 10-bits are obtained). The r0 is encoded with two bits corresponding to its binary value:

B0 ¼ r0ð2Þ ; whilst the all remaining codes are binarised as follows:

3.1. Chain code binarisation models Chain codes are firstly converted into binary streams by taking into account the properties of each particular chain code. Let S ¼ fri g; ri 2 R; i 2 ½0; n  1 be the sequence of n ¼ jSj chain code symbols and let B ¼ fbj g; bj 2 f0; 1g; j 2 ½0; m  1 be the obtained bit-stream with the length m ¼ jBj. The binarisation for the considered chain codes F8, F4, VCC, 3OT, and NAD works as follows.  The alphabet RðF8Þ consists of 8 symbols, which are normally encoded with three bits corresponding to the actual symbol (i.e. r ¼ 0ð10Þ is encoded as 000ð2Þ and r ¼ 7ð10Þ as 111ð2Þ ), which is considered as the less efficient chain code encoding. Hence, it is generally taken as a reference for estimating the efficiencies of various chain code compression algorithms [17]. However, by observing the sequence of F8 symbols, it can be noticed that the consecutive symbol values are correlated; their values are frequently the same or their absolute values differ only slightly. This is because the chain codes describe the boundaries of the geometric shapes and not unpredictably noisy data. The first three bits are determined as the binary code of the first chain code symbol:

B0 ¼ r0ð2Þ ; whilst the all remaining bits are generated by the following rules:

8 Bi1  00 > > > > > Bi1  01 > > > < Bi1  01 Bi ¼ > > Bi1  10 > > > > > Bi1  10 > : Bi1  11  rið2Þ

: ri1 ¼ ri : ri1 ¼ ri þ 1 : ri1 ¼ 7 ^ ri ¼ 0 : ri1 ¼ ri  1 : ri1 ¼ 0 ^ ri ¼ 7 otherwise

where  is a concatenation of bits. Let us consider an example of a shape from Fig. 1a. F8 = {0000024431112244444 6000755556} gives B = {000 00 00 00 00 11010 11100 00 10 11001 00 00 01 00 11100 00 00 00 00 11110 11000 00 00 10 11101 00 00 00 01}, where the runs of 0-bits is apparent.  RðF4Þ has 4 elements in the alphabet that are usually encoded with two bits. However, when considering Fig. 1b it is obvious that the sequence of codes representing 180 angle is very rare, whilst the repetition of the same symbols is more probable and

8 Bi1  0 > > > > > Bi1  10 > > > > > Bi1  110 > > > > > Bi1  111 > > > > > Bi1  10 > > > > > B > < i1  110 Bi ¼ Bi1  111 > > > Bi1  10 > > > > > > Bi1  110 > > > > > Bi1  111 > > > > > Bi1  10 > > > > > Bi1  110 > > : Bi1  111

ri1 ¼ ri ri1 ¼ 0 ^ ri ¼ 1 ri1 ¼ 0 ^ ri ¼ 2 ri1 ¼ 0 ^ ri ¼ 3 ri1 ¼ 1 ^ ri ¼ 0 ri1 ¼ 1 ^ ri ¼ 3 ri1 ¼ 1 ^ ri ¼ 2 ri1 ¼ 2 ^ ri ¼ 3 ri1 ¼ 2 ^ ri ¼ 0 ri1 ¼ 2 ^ ri ¼ 1 ri1 ¼ 3 ^ ri ¼ 2 ri1 ¼ 3 ^ ri ¼ 1 ri1 ¼ 3 ^ ri ¼ 0

: : : : : : : : : : : : :

The chain code F4 ¼ f000001222110101011222223000033232 32323g from Fig. 1b yields B ¼ f00 0 0 0 0 10 111 0 0 111 0 10 10 10 10 10 10 0 111 0 0 0 0 10 111 0 0 0 111 0 10 10 10 10 10 10 10 10g with noticeable runs of 0-bits and {10}-bits.  Alphabet of RðVCCÞ consists of three symbols, amongst which r ¼ 2 is the more frequent [17]. Therefore, the first symbol is binarised by V_VCC as follows:

8 : > <0 B0 ¼ 10 : > : 11 :

ri ¼ 2 ri ¼ 1 ri ¼ 3

Symbols r ¼ 1 and r ¼ 3 are frequently found in sequence. Therefore, the combination of these two symbols is binarised in such a way as to achieve runs of 1-bits. Therefore:

8 Bi1  0 > > > > > Bi1  10 > > > > > > < Bi1  11 Bi ¼ Bi1  10 > > > > Bi1  11 > > > > > Bi1  10 > > : Bi1  11

: : : : : : :

ri1 ¼ ri ri1 ¼ 1 ^ ri ¼ 2 ri1 ¼ 1 ^ ri ¼ 3 ri1 ¼ 2 ^ ri ¼ 3 ri1 ¼ 2 ^ ri ¼ 1 ri1 ¼ 3 ^ ri ¼ 2 ri1 ¼ 3 ^ ri ¼ 1

Let us observe an example from Fig. 2a. VCC ¼ f22222121 223313131221222221 212223313131312g. The obtained binary stream B ¼ f0 0 0 0 0 11 10 11 10 0 10 0 11 11 11 11 11 10 0 11

B. Zˇalik et al. / J. Vis. Commun. Image R. 29 (2015) 8–15

11

Fig. 8. Horse model (a) original, (b) smoothed.

Table 1 NAD coding. Angle-difference (°) Code

0 0

45 1

45 2

90 300

90 310

135 301

135 311

180 312

10 0 0 0 0 11 10 11 10 0 0 10 0 11 11 11 11 11 11 11 10g. As explained, the symbols’ combination {1,3} leads to the runs of 1-bits.  3OT is defined by alphabet Rð3OTÞ ¼ f0; 1; 2g, amongst which all three may form the run sequences. The first symbol is encoded using two bits:

B0 ¼ r0ð2Þ whilst the binarisation of the remaining symbols is performed according to the following rules:

8 Bi1  0 > > > > > Bi1  10 > > > > > > < Bi1  11 Bi ¼ Bi1  10 > > > > Bi1  11 > > > > > Bi1  10 > > : Bi1  11

ri ¼ ri1 ri1 ¼ 0 ^ ri ¼ 2 ri1 ¼ 0 ^ ri ¼ 1 ri1 ¼ 1 ^ ri ¼ 0 ri1 ¼ 1 ^ ri ¼ 2 ri1 ¼ 2 ^ ri ¼ 0 ri1 ¼ 2 ^ ri ¼ 1

: : : : : : :

The chain code from Fig. 2b is 3OT ¼{000001200102 11111020 000220001021111 111} and the binary stream B ¼ {00 0 0 0 0 11 11 10 0 11 10 10 11 0 0 0 0 10 10 10 0 0 0 10 0 10 0 0 11 10 10 11 0 0 0 0 0 0}.

0o

0o

0o

o

0o

90

0o o

45 o

90

o

90

0

o

0

o o

-45

0o

o

-90

o

45

o

-45

o

0

0o

whilst remaining codes are encoded as follows:

8 Bi1  0 > > > > > Bi1  10 > > > > > B  110 > > > i1 > > B  111 > > > i1 > > > B 0 > > i1 > > > B  10 > > i1 > < B  110 i1 Bi ¼ > Bi1  111 > > > > > Bi1  0 > > > > > Bi1  10 > > > > > > Bi1  110 > > > > > Bi1  111 > > > > > Bi1  0 > > : Bi1  10

: : : : : : : : : : : : : :

ri1 ¼ 0 ^ ri ¼ 0 ri1 ¼ 0 ^ ri ¼ 1 ri1 ¼ 0 ^ ri ¼ 2 ri1 ¼ 0 ^ ri ¼ 3 ri1 ¼ 1 ^ ri ¼ 2 ri1 ¼ 1 ^ ri ¼ 0 ri1 ¼ 1 ^ ri ¼ 1 ri1 ¼ 1 ^ ri ¼ 3 ri1 ¼ 2 ^ ri ¼ 1 ri1 ¼ 2 ^ ri ¼ 0 ri1 ¼ 2 ^ ri ¼ 2 ri1 ¼ 2 ^ ri ¼ 3 ri1 ¼ 3 ^ ri ¼ 0 ri1 ¼ 3 ^ ri ¼ 1

The following sequence of relative angles is obtained from Fig. 4: D ¼ f0 ; 0 ; 0 , 0 ; 0 ; 90 ; 90 ; 0 ; 45 ; 90 ; 0 ; 0 ; 45 ; 0 ; 90 ; 0 ; 0 ; 0 ; 0 ; 90 ; 90 ; 0 ; 0 ; 45 ; 90 , 0 ; 0 ; 0 ; 45 ; g. By using of Table 1, a sequence of the chain code symbols is obtained: NAD ¼{0000030030002310001030000003003000023100001} and from it B={00 0 0 0 0 111 0 0 111 0 0 0 110 111 10 10 0 0 10 10 111 0 0 0 0 0 0 111 0 0 111 0 0 0 0 110 111 10 10 0 0 0 10}. Besides runs of 0-bits, patterns of repeating bits’ combinations can be easily noticed.

The aim of the second step of the algorithm is to replace the runs of 1-bits with the runs of 0-bits. In this case the runs of only

o

-90

0o

B0 ¼ r0ð2Þ

3.2. d-coding

0o

0o 0o

 The normalised angle-difference chain code NAD has been introduced by [21] and is turning out to be the most efficient and compressible chain code in the majority of cases. RðNADÞ ¼ f0; 1; 2; 3g, where r ¼ 3 is a guard indicating that the next code has an angle greater that j45 j. The coding scheme for NAD is shown in Table 1. The first symbol is encoded by two bits, therefore:

o

0o

90

0o

0

o

o

90

0o

Fig. 4. The relative angles are the bases for NAD coding.

0-bits would need to be considered, which is then used by RLE0 mode during the next step of the UCCC. The algorithm checks each input bit and outputs 0, if the current and the previous bits are the same, otherwise, it generates 1. Let B ¼ fb0 b1 . . . bn1 g be the input bit stream and Q ¼ fq0 q1 . . . qn1 g its output. Its d–transform is obtained as follows:

q0 ¼ b0 :

B. Zˇalik et al. / J. Vis. Commun. Image R. 29 (2015) 8–15

12

For 8i; 0 < i < n

qi ¼



0 : pi1 ¼ pi 1 otherwise:

For example, when applying d-coding on the VCC bit stream from our example above B ¼ f0 0 0 0 0 11 10 11 10 0 10 0 11 11 11 11 11 10 0 11 10 0 0 0 0 11 10 11 10 0 0 10 0 11 11 11 11 11 11 11 10}, the result is Q ¼{0 0 0 0 0 10 01 10 01 0 11 0 10 00 00 00 00 01 0 10 01 0 0 0 0 10 01 10 01 0 0 11 0 10 00 00 00 00 00 00 01}, where the runs of 1-bits have been transformed into the runs on 0-bits. As seen in Fig. 3, d-coding is applied for F4 and VCC. 3.3. Entropy coding In this step the binary stream of chain codes is compressed. The algorithm may select from three modes (see Fig. 3): 1. In RLE0 mode, the runs of 0-bits are encoded by outputting flag R followed by r-bits describing the number of 0-runs. As the binary stream is compressed, it is clear that after the 0-runs at least one 1-bit exist. This 1-bit therefore does not need to be encoded; it is passed-over for compression and automatically generated at the decompression. This, however, could wrongly insert additional 1 bit during decompression at the end of the bit stream, if RLE0 was the latter used mode. Fortunately, such a case is easily detectable and solved during decompression. 2. Mode LZ770 is our simplified version of the well-known LZ77 sliding window compression algorithm [23]. The sliding window consists of the body and the buffer. The body contains the so-called dictionary and is considerably larger than the buffer, which contains the message to be encoded. The algorithm searches for the longest match of the message within the buffer against the body. The LZ77 outputs a token consisting of three values: the offset, the length of the longest match, and the code of the next symbol. The coding of the next symbol is needed to escape from a situation when no match exists. LZ770 is considerably simpler. The longest match is always searched for from the last symbol of the body and therefore the number of the matched symbols and the offset are the same and need to be stored only once. Furthermore, the outputting of the next symbol is unnecessary; if no (or too short) match exist, the algorithm switches to one of the other two modes. Therefore, the token of the LZ770 mode contains the flag Z followed by r-bits determining the number of bits denoting the length of the match.

Fig. 5. Pseudocode of the compression algorithm.

at all (2 bits are used for Z flag). On the other hand, if, for example, r ¼ 8, 256 0-bit runs can be described. Such long runs occur very rarely leading again to the low compression as we would have wasted the most-significant r bits. The reasonably expected number of 0-bit runs turns to be in-between, i.e. at r ¼ 5 bits when the 2r ¼ 32 0-bits runs can be expressed. In such a case, each RLE0 command spends 7 bits (2 bits for R flag followed by 5 r bits). Shorter runs leads to the expansion. Therefore, it is sensible to switch to the RLE0 compression mode only, when the runs of 0-bits is equal or longer than 7. The shortest runs are therefore encoded differently, i.e. by COPY mode, and c ¼ r  1 ¼ 6. In this way the range of 0-runs expressed by r ¼ 5 bits becomes ½7; ð25 Þ þ 7  1 ¼ 38. The same consideration is used for the mode LZ770 .

3.4. Forming the output stream The last step of the algorithm consists of three parts:

0

3. Mode COPY. This is the escape mode, when neither RLE nor LZ770 can be efficiently used. In such a case the bits from the input are directly copied to the output. The mode is marked by the flag C, which is followed by the c copied bits. The algorithm always determines the number of 0-bits runs and 0

the number of the longest LZ77 match. The longest of them is, of course, used. However, COPY mode is applied if in both modes too few bits are obtained. The pseudocode of the algorithm is shown in Fig. 5. The parameters c and r are related and are determined according to the following observation. The presented compression algorithm uses three modes, the flags of which (C; R; Z) can be encoded with two bits. Let us only consider the RLE0 mode at this stage. If r (the number of bits reserved for describing the 0-bit runs) would be, for example, 2, the runs of only 4 0-bits could be described. Clearly, this is too short and would not lead to the compressions

 determining the codes of flags C; R, and L,  determining the orphan bits, and  forming the output binary file. The number of used C; R, and L flags is counted during the compression process. The more frequently used flag is encoded with 0bits, whilst the remaining two flags with bit combinations 10 and 11. There are three possibilities as shown in Table 2. Orphans are bits at the end of the input bit streams the lengths of which are shorter than the c bits, and therefore they cannot be expressed by any of the algorithm’s modes. One of the solutions would be to introduce a terminal flag, that would, unfortunately, increase the number of the algorithm’s flags. The more efficient solution is used by the proposed method that stores the orphans at the beginning of the output file. The output file consists of a header and a body (Fig. 6). The header contains the following parts:

B. Zˇalik et al. / J. Vis. Commun. Image R. 29 (2015) 8–15

 the first three bits (P1 in Fig. 6) are used to define the chain code being compressed, i.e. 000 stands for F8, 100 for NAD;  the next two bits (P2 in Fig. 6) contains the information about C; R, and Z flag coding according to Table 2;  the following three header bits describe the number of orphan bits (P3a on Fig. 6) followed by the orphans (P3b in Fig. 6).

13

header

P1

P2

P3a

body

P3b

Q

Fig. 6. The structure of the output file.

The body stores the binary stream Q, where the flags C; R, and Z are replaced by the binary codes as defined in Table 2.

4. Results The proposed lossless chain code compression algorithm was tested on various benchmark shapes, as shown in Fig. 7 (they can be obtained at http://gemma.uni-mb.si/chaincodes/). The characteristic information about them is summarised in Table 3. Besides the number of codes (n), the sizes of the bit streams jBj after the binarisation are also given. The results of the proposed algorithm are given in Table 4, where the best compression for each shape is highlighted in bold. In the majority of cases, the best results were achieved with NAD. Surprisingly, F8 was frequently the second better followed by 3OT; VCC, and F4. Two shapes (horse and tiger) did not follow this pattern; indeed, 3OT was the best whilst F8 and NAD were the worst. The reason for this can be explained by closer inspections of these shapes (in Fig. 8a an enlarged shape horse is shown). We can easily estimate it as being rough with many 90 turns. These turns means that the Freeman’s values of neighbouring codes differ

Table 2 Coding the C; R, and L flags. Flags’ code

The most frequent flag

Codes for the flags

1 2 3

C R Z

C ¼ 0; R ¼ 10; Z ¼ 11 R ¼ 0; C ¼ 10; Z ¼ 11 Z ¼ 0; R ¼ 10; C ¼ 11

by more than j1j meaning that such neighbours were encoded using 5 bits. NAD on the other hand encodes 90 angles with three codes, whilst for smaller angles only one code is used (see Table 1). This is the reason, why the size of the binarised stream shown in Table 3 is considerably larger in these cases (8885 bits for F8 and 6925 for NAD against 5697 for 3OT). Unsurprisingly, the shapes horse and tiger were also well-compressed with F4, which encodes only 90 angles between neighbouring codes. Fig. 8b shows the smoothed shape of the horse. As the majority of the transitions between the neighbouring codes have the slope 45 or less, we can expect that the F8 binarisation will be efficient. The results are shown in Table 5. As seen, F8 contains considerably less chain codes, which are in additionally encoded with just 2 bits, leading to the second better compression. The situation is even better with NAD, where the shape was also encoded with a small number of symbols that were very efficiently binarised, thus providing the smallest output. Other chain codes (F4; VCC; 3OT) produced worse results than in the case of the rough horse shape (compare Tables 4 and 5). It can be concluded from these results that the F8 and NAD chain codes are more suitable for the compressions of smooth shapes, whilst the remaining three chain codes work better for rough shapes with many 90 turns. The UCCC was compared at the end to the chain code compression method using Move-to-front transformation and adaptive run-length encoding [21], which showed the better lossless compression abilities from amongst all the known compression methods. As F8 and F4 had not been used in previous experiments, the comparison was done with VCC; 3OT, and NAD chain codes on the

Fig. 7. Shapes for testing.

B. Zˇalik et al. / J. Vis. Commun. Image R. 29 (2015) 8–15

14

Table 3 Testing geometric shapes and number of bits after binarisation. Shape

nF8

jBF8 j

nF4

jBF4 j

nVCC

jBVCC j

n3OT

jB3OT j

nNAD

jBNAD j

Bird Butterfly Circle Fire Horse Plane Shuttle Spider Square Star Thunder Tiger

1733 1379 756 778 3953 1492 969 1769 1092 1024 682 786

3530 2789 1513 1572 8885 3015 1963 3557 2194 2070 1386 1747

2372 2008 1068 1151 4310 2260 1232 2585 1092 1448 1063 864

4256 3913 2005 2009 5809 4475 2026 5050 1097 2726 2488 1237

2377 2013 1073 1149 4315 2265 1237 2586 1097 1452 1071 867

4070 3688 1879 2114 5710 4127 1936 4694 1105 2503 2112 1161

2376 2012 1072 1149 4314 2262 1236 2586 1096 1452 1074 870

3621 3260 1661 1807 5697 3218 1721 4004 1105 2063 1918 1148

1775 1399 756 788 4605 1512 985 1781 1098 1038 698 891

2635 2077 1052 1117 6925 2023 1363 2623 1105 1480 960 1301

Table 4 Results of compression in bits for various shape and various chain codes. The best results are marked in bold. Shape

F8

F4

VCC

3OT

NAD

Bird Butterfly Circle Fire Horse Plane Shuttle Spider Square Star Thunder Tiger

2977 2359 1214 1074 5839 1066 1215 2608 393 784 601 1212

3251 2753 1225 1113 4689 1480 1320 2815 209 896 1130 1054

3160 2738 1232 1093 4690 1345 1268 2789 226 829 841 1027

3099 2651 1122 1007 4283 1144 1172 2683 226 781 713 990

2570 1988 974 948 5733 846 1115 2301 209 684 468 1193

Table 7 Runtimes speed comparison between the MTFT-ARLE and UCCC methods. All times are in milliseconds. Shape

MFTF-ARLE

UCCC

VCC

3OT

NAD

F4

F8

VCC

3OT

NAD

Bird Butterfly Circle Fire Horse Plane Shuttle Spider Square Star Thunder Tiger

13 12 5 11 30 5 5 16 4 7 14 20

12 9 4 20 34 6 5 15 3 7 8 16

38 21 11 17 64 24 28 29 19 18 14 18

22 24 15 16 39 24 19 31 16 19 22 17

20 17 14 15 55 17 19 18 32 23 18 18

20 23 17 17 42 22 19 29 14 18 20 17

19 17 13 10 32 15 13 22 13 23 14 23

21 17 14 16 48 19 18 22 18 19 18 19

Table 5 Smoothed shape horse.

F8 F4 VCC 3OT NAD

n

Binarisation (bits)

Compression (bits)

2948 3924 3891 3893 2950

5990 6809 6539 5997 4210

5028 5562 5552 5114 4205

UCCC; RLE0 LZ 0 are always tested, which performs the best in the

Table 6 Comparison between the MTFT-ARLE and UCCC methods. The best results are marked in bold. Shape

bird butterfly circle fire horse plane shuttle spider square star thunder tiger

MFTF-ARLE

In Table 7 the comparison of spent CPU time for UCCC and MTFT  ARLE methods. In general, MTFT  ARLE is faster. The reason for this is the binarization, which generates the longer sequence of symbols (bits) than the original chain code. In concrete situation. LZ 0 has to compare the bits forward and backward from the current position. On the other hand MTFT  ARLE switches only between two variants of RLE method what eventually represents smaller load for the computer. 5. Conclusion

UCCC

VCC

3OT

NAD

VCC

3OT

NAD

2897 2308 1073 1117 4409 1553 1233 2763 355 1574 582 1073

2733 2141 1053 1100 4855 1543 1205 2656 355 1566 529 977

2699 2025 917 940 5690 1370 1181 2127 331 1004 576 1176

3160 2738 1232 1093 4690 1345 1268 2789 226 829 841 1027

3099 2651 1122 1007 4283 1144 1172 2683 226 781 713 990

2570 1988 974 974 5733 846 1115 2301 209 684 468 1193

same benchmark shapes as used in [21]. The results are summarised in Table 6. It can be concluded from the results that UCCC is very competitive on all considered chain codes. However, both algorithms work in time OðnÞ.

This paper has presented a new universal lossless chain code compression method (UCCC). Different binarisation schemes are used for different chain codes, leading to universal input for further compression. The binarisation rules are oriented towards the same bit-runs. The bit-stream is compressed by switching between three modes: RLE0 compresses runs of 0-bits, a simplified version of LZ77–LZ770 encodes the repeating parts of the bit stream, whilst the COPY mode is an escape mode used in the cases, when RLE0 and LZ770 are inefficient. The experiments yielded interesting conclusions. The Freeman chain code in eight directions (F8) is more compressible than Freeman chain code in four directions (F4), the Vertex chain code (VCC), or even the Three OrThogonal chain code (3OT). The most compressible chain code is the normalised angle difference (NAD). However, NAD and F8 are sensitive to roughness of the geometric shape. They become inefficient for shapes with many 90 turns between neighbouring codes. In the case of F8 this is due the binarisation rules, whilst NAD encodes greater angles

B. Zˇalik et al. / J. Vis. Commun. Image R. 29 (2015) 8–15

than 45 with three codes. It would be easy to analyse the input chain code at first and then heuristically choose the best code or change the binarisation rules. As recently shown by Sánchez-Cruz and López-Valdez [24], the chain codes can be directly converted from one to another; a feature which can be efficiently included in the proposed algorithm. Acknowledgement This work was supported by the Slovenian Research Agency under Grants J2-5479 and 1000-13-0552. This paper was produced within the framework of the operation entitled Centre of Open innovation and ResEarch UM. The operation is co-funded by the European Regional Development Fund and conducted within the framework of the Operational Programme for Strengthening Regional Development Potentials for the period 2007 2013, development priority 1: Competitiveness of companies and research excellence, priority axis 1.1: Encouraging competitive potential of enterprises and research excellence. References [1] X. Dai, S. Khorram, A feature-based image registration algorithm using improved chain-code representation combined with invariant moments, IEEE Trans. Geosci. Remote Sensing 37 (5) (1999) 2351–2362. [2] 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. [3] T. Globacˇnik, B. Zˇalik, An efficient raster font compression for embedded systems, Pattern Recogn. 43 (12) (2010) 4137–4147. [4] R.K. Gupta, B. Gurumoorthy, Automatic extraction of free-form surface features (ffsfs), Comput. Aid. Des. 44 (2) (2012) 99–112. [5] 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. [6] 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.

15

[7] M. Ren, H.A. Karimi, A chain-code-based map matching algorithm for wheelchair navigation, Trans. GIS 13 (2) (2009) 197–214. [8] H. Sun, J. Yang, M. Ren, A fast watershed algorithm based on chain code and its application in image segmentation, Pattern Recogn. Lett. 26 (9) (2005) 1266– 1274. [9] 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. [10] H. Freeman, On the encoding of arbitrary geometric configurations, IEEE Trans. Electron Dev. 10 (2) (1961) 260–268. [11] P. Nunes, F. Pereira, F. Marqués, Multi-grid chain coding of binary shapes, ICIP’97 Proceedings of the 1997 International Conference on Image Processing, vol. 3, IEEE Computer Society, DC, USA, 1997, pp. 114–117. [12] E. Bribiesca, A new chain code, Pattern Recogn. 32 (2) (1999) 235–251. [13] H. Sánchez-Cruz, R.M. Rodríguez-Dagnino, Compressing bi-level images by means of a 3-bit chain code, SPIE Opt. Eng. 44 (9) (2005) 1–8. [14] 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. [15] H. Hampel, R.B. Arps, C. Chamzas, D. Dellert, D.L. Duttweiler, T. Endoh, W. Equitz, F. Ono, R. Pasco, I. Sebestyen, C.J. Starkey, S.J. Urban, Y. Yamazaki, T. Yoshida, Technical features of the JBIG standard for progressive bi-level image compression, Signal Process.: Image Commun. 4 (2) (1992) 103–111. [16] Y.K. Liu, B. Zˇalik, An efficient chain code with huffman coding, Pattern Recogn. 38 (4) (2004) 553–557. [17] Y.K. Liu, W. Wei, P.-J. Wang, B. Zˇalik, Compressed vertex chain codes, Pattern Recogn. 40 (11) (2007) 2908–2913. [18] 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. [19] H. Sánchez-Cruz, Proposing a new code by considering pieces of discrete straight lines in contour shapes, J. Visual Commun. Image Represent. 21 (4) (2010) 311–324. [20] B Y.-K. Liu, 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. [21] 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. [22] E. Lemus, E. Bribiesca, E. Garduno, Representation of enclosing surfaces from simple voxelized objects by means of a chain code, Pattern Recogn. 47 (4) (2014) 1721–1730. [23] J. Ziv, A. Lepel, A universal algorithm for sequential data compression, IEEE Trans. Inform. Theory 23 (3) (1977) 337–343. [24] H. Sánchez-Cruz, H.H. Lopez´-Valdez, Equivalence of chain codes, J. Electronic Imaging 23 (1) (2014) 13–31.