You are on page 1of 8

Image representation by using chain code

Abstract Shape-of-object representation has always been an important topic in image processing and pattern recognition. This work deals with representation of shape based on a new boundary chain code, and uses this chain code to recognize the object. Chain code techniques are widely used to represent an object because they preserve information and allow considerable data reduction. In this report the vertex chain code (VCC) is presented, this chain code is based on E. Bribiesca for shapes composed of regular cells . Also, the report discusses the capabilities of the VCC in recognizing objects, the results show that, the VCC recognizes images better than the classical methods. Introduction The first approach for representing digital curves using chain code was introduced by Freeman in 1961 [3]. Classical methods for processing chains are referred to [4]. Freeman [4] states that in general, a coding scheme for line structures must satisfy three objectives: (1) it must faithfully preserve the information of interest; (2) it must permit compact storage and convenient for display; and (3) it must facilitate any required processing. Also the VCC comply with these three objects, and has some important differences. E. Bribiesca [1] states some important characteristics of the VCC: (1) The VCC is invariant under translation and rotation, and optionally may be invariant under starting point and mirroring transformation. (2) Using the VCC it is possible to represent shapes composed of triangular, rectangular, and hexagonal cells. (3) The chain elements represent real values not symbols such as other chain codes, are part of the shape, indicate the number of cell vertices of contour nodes, may be operated for extracting interesting shape properties. (4) Using the VCC it is possible to obtain relations between the bounding contour and interior of the shape. In this report uses the classical methods and the VCC method for computing the chain code. The images considered here are binary images with outer contour. In other words there are not any holes in the objects. Also, we will show how you can use these chain codes to recognize to the object. This report is organized as follows. Section (1) presents chain code properties. Section (2) presents a new method for extracting the contour of a binary image. Section (3) shows a simple example to compute the classical and the vertex chain code. Section (4) using 2 method to solve the scaling problem. Section (6)Practical work. Finally, Section (6) some conclusions are given.

1 CHAIN CODE Properties: >Chain codes describe an object by a sequence of unit-size (4 or 8-connectivity) line Segments with a given orientation. >The first element of such a sequence must bear information about its position to allow reconstruction of the region. >Even codes{0,2,4,6}corresponding to horizontal and vertical directions; odd codes {1,3,5,7} correspond to the diagonal directions. >Each code can be considered as the angular direction, in multiples of 25 degrees that we must move to go from one contour pixel to the next. >The absolute coordinates of the first contour represent complete description of the discrete region contour. >When there is a change between two consecutive chain codes, then the contour has changed direction. This point is defined as a corner.

2 Boundary extraction
The first step of the construction of the chain code is to extract the boundary of the image. Chains can represent the boundaries or contours of any discrete shape composed of regular cells. In the content of this work, the length l of each side of cells is considered equal to one. These chains represent closed boundaries. Thus, all chains are closed. Extracting the contour depends on the connectivity. In the content of this report uses pixels with four-connectivity. The simplest contour following algorithms were presented by Papert [8] and Duda and Hart [7]. Thus using these algorithms it is possible to represent shape contours by only two states: left turn (represented by 1") and right turn (represented by 0"). The above mentioned process produces a chain composed of only binary elements. Figure (1) illustrates the contour following on an image composed of pixels. This contour was obtained according to the following algorithm:

Figure 1: Example of a contour following In a digital figure. .

Figure 2: Directions of the neighbors :( a) 4-connected; (b) 8-connected.

-Scan the picture until a figure cell is encountered, Then: -If you are in a figure cell turn left and take a step. -If you are in a ground cell turn right and take a step. -Terminate when you are within one cell of the starting point. In this report proposed a new algorithm to find the contour of a binary image and use this contour to obtain the chain code. Since we use pixels with 4-connectivity, the four neighbors of any point can be represented by directions as illustrated in figure (2a). To find the contour of a binary image we apply the following algorithm: Step1: For all pixels with value 0 (black) in the image, set the pixel that has the direction 2 in 4-connected to 0. Step2 : In the new image (i.e., image obtained from Step 1), also, for all pixels with value 0, set the pixel that has the direction 1 in 4-connected to 0. Step3 : Remove the old pixels (in the original image) that have 8-connected as shown in figure (2b) and do not satisfy the conditions shown in figure (3).

Figure 3: Four conditions to remove the old pixels.

Example: if we apply the previous algorithm to the three images shown in figure
(4), we will obtain the contour of the images as depicted in figure (5).

Figure 4: Three simple binary images.

Figure 5: The three steps for finding the contour of the binary images shown in figure (4).

Figure (5a) shows Step 1 of the algorithm, figure (5b) represents Step 2 to find the contour of a binary image, and figure (5c) shows Step 3 of the algorithm.

Note that, we can apply this algorithm to real images to obtain their contours. Figure (6) shows a tree (a) leaf and its contour (b). Also, the previous algorithm can apply to obtain the contour of the binary images even if these images with holes.

Figure 6: A tree leaf: (a) the original image; (b) Contour of the image.

Figure (7) shows the contour of an image with two holes.

Figure 7: Image with two holes: (a) original image; (b) Its contour.

3 The classical and the vertex chain code Chains can represent the boundaries or contours of any image. The classical (Freeman) chain is defined as the direction of the objects contour from starting point [6], while an element of the VCC indicates the number of cell vertices, which in touch with the bounding contour of the shape in that element position [1]. Figure (8a) presents a shape composed of pixels with its directions. Figure (8b) shows the same shape with its VCC elements. Figure (8c) shows the classical chain code of the shape. Figure (8d) shows the VCC of the shape. Note that when we are using pixels; the VCC has only three different numbers of cell vertices for the bounding contour: 1, 2, and 3 [1]. The classical and the vertex chain code may be invariant under starting point and rotation by using the concept of the shape number. The shape number of the classical chain can be derived from the chain code by taking the difference of the elements of the chain code in counterclockwise direction to obtain the difference code, then rotate the digits of the difference code until the number is minimum to obtain the shape number. The shape number of the VCC can be obtained directly by rotating the digits of the chain until the number is minimum.

The difference code of the classical chain code shown in figure (8c) is 10101131, and its shape number is 0101131 1. Also, the shape number of the VCC shown in figure (8d) is 11212113. Note that, the shape number is invariant under rotation. It means that, if the object is rotated with k (/2) where k is an integer, the shape number is the same.

Figure 8: The classical and the vertex chain code: (a) A shape composed of pixels; (b) the same shape; (c) The elements of the classical chain code; (d) The elements of the VCC.

4 Scaling problem The chain code is translation invariant and it is not scale invariant. Figure (9) shows how the chain code is varying if the shape is scaling. Nevertheless, the shape code is not scale invariant. If the elements of the chain code are multiplied n times, the object will enlarge k times depending on n. But the shape number does not have this feature. On the other hand, if the chain code is transformed back from the shape number anyhow, then the chain code will be as original chain code. It means that if you have some different chain codes of an object, you have to transform these into a shape number and back and the solution will be the same chain.

Figure 9: Scaling problem: (a) a simple shape; (b) the shape after scaling; (c) the classical chain of the image in (a); (d) the classical chain of the image in (b).

Now the problem can be defined. Let two objects without holes f(x, y) and g(x, y). The classical chain code of image f is cf and the classical chain code of image g is cg. The question is the following: can the binary object f(x, y) be matched to the object g(x, y) with any scaling or rotation by k (/2), where k is an integer.

4.1 The 2 method The 2 test is a common method to verify if two given set of data belongs to the same of different distribution. Compute the original chain codes cf and cg. Then look on these codes as two random variables and the elements of these codes as samples of these random variables. Detail the random variable with the cf and let the sample be (1, ..., m) with m elements. Detail the random variable with cg as well. Let the sample be (1, ..., n) with n elements. Examine the homogeneity of these variables with the 2 test, because if one of these chain codes differs only from the other chain code only in scaling, then they can be considered as two samples of one population. The set of the values of and is the set {0, 1, 2, 3}, because these are classical chain codes. Divide the values of and into four sets. Let v0 is the number of 0" in , v1 is the number of 1" in , v2 is the number of 2" in , and v3 is the number of 3" in . Also, let u0, u1, u2, and u3 are the number of 0", 1", 2", and 3" in , respectively. Then the 2 is given by:

It can be proven that if m and n are large enough and the codes can be matched together anyhow, then the distribution of test statistic 2 is approximately a 2 distribution with 4 degree-of-freedom.

Example: the original chain code of the image in figure (12a) is 0 0 1 1 2 3 2 3 and
the original chain code of the image in figure (12b) is 0 0 0 0 1 1 1 12 2 3 3 2 2 3 3. Now, let = (0, 0, 1, 1, 2, 3, 2, 3) and = (0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3). Then: v0 = 2 , u0 = 4; v1 = 2 , u1 = 4; v2 = 2 , u2 = 4; v3 = 2 , u3 = 4; and R0 = 0 R1 = 0 R2 = 0 R3 = 0 *So, the 2 is zero: 2 = 0

5 Practical work 1- Implement the border tracing algorithm and draw the object contour on an image having a single object. 2- Starting from the border tracing algorithm write the algorithm that builds the chain code and derivative chain code for an object. Compute and display both codes (chain code and derivative chain code) for an image with a single object.

3- Implement a function that reconstructs (draw) the border of an object over an image having as inputs the start point coordinates and the chain code in 8-neighborhood, load the image and apply the function that reconstruct the border. 6 Conclusion In this report, a new method for extracting the contour of binary images is presented. The new method can apply to any binary image with or without holes. The extracted contour is used to derive the chain code of the image. The classical (Freeman) and a new chain code for shapes composed of finite number of cells are defined. The definition of the new chain code (termed vertex chain code, VCC) is valid for shapes composed of triangular, rectangular, and hexagonal cells. The VCC preserves information and allows considerable data reduction. This chain code is invariant under translation and rotation, and optionally, under starting point and mirroring transformation. To illustrate the capabilities of the VCC. Finally, we use the 2 method to solve the problem of scaling. Since the chain code is not scale invariant. In the scaling problem, the classical chain code gives better results References [1] E. Bribiesca. A new chain code. Pattern Recognition,32:235251, 1999. ICGST-GVIP Journal, Volume 5, Issue3, March 2005 [2] Abdel-Badeeh M. Salem, Adel A. Sewisy, Usama A. Elyan. A Vertex Chain Code Approach for Image Recognition. [3] H. Freeman. On the encoding of arbitrary geometric configurations. IRE Trans. Electron.Comput. EC, 10:260268, 1961. [4] H. Freeman. Computer Processing of line drawing images. ACM Comput. Surveys, 6:5797,1974. [5] R. Wagner and M. Fischer. The string-to-string correction problem. Journal of the ACM, 21:168173, 1974.

[6] R.C. Gonzales and R.E. Woods. Digital image processing, second edition. Addison-Wesley, 2002 [7] R.O. Duda and P.E. Hart. Pattern classification and scene analysis. Wiley, New York, 1973. [8] S. Papert. Uses of technology to enhance education. Technical Report 298, AI Lab, MIT, 1973.

You might also like