Doc. RNDr. Stanislav Barton, CSc. Mendel university of Agriculture and Forestry in Brno Agronomical faculty Dept. of Automobile transport and principles of technics Zemedelska 1; 61300 Brno ++ 05 4513 2127 barton@mendelu.cz Identification and Recognition of Leaves and General 2-D Objects
Part 1: - Transformation of DXF file into a parametric function Theory: The outline of an arbitrary complicated 2D object can be approximated by a polygon consisting of a finite number of line segments. A scanned image can be converted into line segments by the program Adobe Streamline or similar, and the resulting outline can be saved as DXF file = Data Exchange Format. The [x, y] coordinates of polygon vertices can be found in this file. The simplest approximation of such a polygon can be done by a couple of parametrically dependent functions .The main question is the proper selection of such a parameter an ordinary number of the verticies can be an example of the parameter. But for other manipulations this parameter will be very important. If the parameter is a length from the initial point on the perimeter, measured along the perimeter normalized to 2 , Fourier series can be used. As is shown in the section Fourier and results from the orthogonality of goniometric functions, it is possible to compute Fourier coefficients independently, not only for x and y functions, but these coefficients are independent. The objects outline is converted into a couple of smooth continuous functions defined on the interval <0, 2 > . These functions can be described by the lists of coefficients and can be used to compute the similarity of two different objects, described by the coefficients of the linear correlation, for example. These coefficients will be computed in the first part.
Reading of the procedures
Procedure DXFREAD
The procedure reads the input DXF file and looks for x and y coordinates of the polygon describing the perimeter of the given object. Coordinates are read step by step as they are ordered in the input file. Coordinates are saved in the variables X and Y of type list. Procedure's input is the name of the file, without extension, containing DXF data. The output is two rlists of vertices, one for x coordinates and one for y.
Procedure SOLAO
Procedure orients the object in the coordinate system. The line of orientation is chosen to minimize the moment of inertia (with respect to the axis of rotation in the xy plane). So the parameters k and q minimize , where k and q are parameters describing the general line , ds = element of the curve (perimeter) and r = distance of the element of the curve ds from the line. The procedure finds two such lines, mutually perpendicular. One leads to a minimum of J(k,q) the second one to a maximum. The whole object is shifted so that the intersection of these lines will be identical with the origin of the coordinate system [0,0] , and rotated so that line with the minimum moment of inertia will coincide with the x axis. This leads to identical orientation of all objects. Because the object (polygon) is created from line segments, it is possible to use the following law to simplify computation => , where N = count of found vertices, thus N-1 line segments, p = parameter describing line segment The Maple functions makeproc and optimize were used to derive this procedure. Procedures inputs are lists X and Y of coordinates of the vertices. The procedure changes the values of X and Y inplace.
Derivation of the procedure SOLAO
Sense of the procedure
"Converting DXF file into lists of coordinates of vertices"
"102 vertices found"
"Looking for center and axis of symmetry"
"Shift =[-3.846728402, -2.137677566]"
"Rotation = 2.201621101*degrees"
Procedure PHASE0
Parametric functions are used to describe a given object, therefore it is advantageous to set 0 to the value of the parameter so that the corresponding point will have always the same positional = phase angle. This procedure is searching for the point situated on the x axis, and its x coordinate is maximal. The procedure later reorders the lists of coordinates in that way, so this point will be the first one, but the shape of the object will be preserved. Inputs and outputs of the procedure are lists of the coordinates of the vertices..
"Setting 0 to initial phase"
"Zero point = [3.537382891, 0]"
Procedure FOURIER
Procedure Fourier computes coefficients of the Fourier series substituting piecewise defined functions x(p) and y(p) , 0 <= p <= L ,( L = distance of the point [x(p),y(p)] , from the initial point, [x(0),y(0)] measured along the perimeter). Fourier series will create smooth continuous functions defined on the interval <0,2 > . The procedures entries are the lists of the coordinates of the vertices, the third parameter indicates the number of the members of the series, outputs are the lists of the Fourier coefficients
Derivation of the procedure FOURIER
"Computing 40 Fouriere's coefficients"
X0 = -.1328943774e-7
Cx[1] = 2.900225949, Sx[1] = .1419823020
Cx[40] = .4754955872e-3, Sx[40] = .3202506275e-2
Y0 = .3724225667e-7
Cy[1] = .6723654211e-1, Sy[1] = -1.715950597
Cy[40] = .1312131189e-2, Sy[40] = .1486127291e-2
Increasing the number of the Fourier coefficients decreases the error of the approximation.
Processing
`"Converting DXF file into lists of coordinates of vertices"`
`"574 vertices found"`
`"Looking for center and axis of symmetry"`
`"Shift =[-12.21275220, -9.483011334]"`
`"Rotation = 3.418483572*degrees"`
`"Setting 0 to initial phase"`
`"Zero point = [9.226803319, 0]"`
`"Computing 50 Fouriere's coefficients"`
`X0 = -.2212253708e-6`
`Cx[1] = 8.672002591, Sx[1] = -1.017347828`
`Cx[50] = -.1191587246e-1, Sx[50] = -.1287842212e-1`
`Y0 = .1917817064e-6`
`Cy[1] = -.8152692550, Sy[1] = -6.792215980`
`Cy[50] = .2360530589e-1, Sy[50] = -.1289477692e-1`
Part 2: - Computation of the transformation parameters, (mutual rotation, shift, rescaling and phase shift) of two different objects using Least Square Method and computing of the Coefficient of the Linear Correlation,.
Theory: The Least Square Method is used to determine the parameters of the transformation. These parameters are:
K = rescaling of the first object
Dx, Dy = shift of the first object in x and y
a = rotation of the second object f = phase shift of the second object,
which will minimize .
With respect to ortogonality of individual terms of Fourier series creating Fx, Fy, Gx and Gy, it is possible to use a lot of simplifications leading to an exact analytical value of the integral mentioned above. The analytical solution of a, Dx, Dy a K can be determined from this value. The value of f can be found by its direct minimization.
If the exact values of transformation are known, it is possible to create new transformed functions FX, FY, GX and GY , where: ,
.
Similarity of the transformed objects will be described by the coefficient of the linear correlation computed below.
, ,
,
Procedure KAF
Procedure KAF computes parameters of the transformation of two objects, resulting in a maximal similarity of both objects. The computation will be finished when the step size of the variable f , (see main page) is lower than a desired correctness = the third parameter.. The fourth, optional parameter is the number of lines connecting the corresponding points on perimeters of both transformed objects. If value of this parameter is 0 , both transformed objects are plotted without lines. If this parameter is missing, the procedure will not create graphical output. The procedure creates new parametric dependent functions describing both transformed objects, saved as new global variables x1, y1, x2 and y2 . Entries of the procedure are filenames containing coefficients of the Fourier equations describing the first and second object. The third parameter is the desired correctness step of f . The four optional parameter controls graphical output.
Derivation of the procedure KAF
Simplified functions describing x and y coordinates of the first (Fx, Fy) and second (Gx, Gy) objects
The first object will be rotated through angle a and shifted by Dx and Dy.
The phase of the second object will be shifted by f and object will be rescaled by a factor of K
Squared distance of the corresponding points of the first and second objects = squared residual. Output is too long, so it is not presented.
Procedure COREL
The procedure computes coefficients of linear correlation of two functions, R1(p) and R2(p) . These functions are created from two pairs of input functions: and , see main file for details. The Simpsons rule is used for numeric integration. As the coefficient of the linear correlation approaches 1, the similarity increases. Zero value indicates no similarity of objects. Entries of the procedure are four functions x1(p), y1(p), x2(p) and y2(p) describing parameter dependence of x and y coordinate of the first and second object. The fifth parameter controls the relative accuracy of the numeric integration.
"f = .2, df = .1, MIN = 4.74937257675374613"
"f = .16784667968750, df = -.1220703125e-4, MIN = 4.69629115004216838"
"_____________________________________________"
"Rotation of Maple1.sav = 8.0004480430310438605*degrees"
"Phase shift of Maple2.sav = 9.6176057627489623335*degrees"
"Scale of Maple2.sav = 2.7941995986574304523"
P1 = 7.912570760
V1 = 2.837610148
P2 = 7.785024297
V2 = 2.514006750
C12 = 1.944717629
Conclusion:
The presented algorithm can be used as an instrument to determine rate of similarity of simple two-dimensional objects. Its advantage is simplicity and possibility of conversion into source files of other programming languages. These procedures were designed for minimization of computer memory consumption, and so Maple special functions were not used, because these functions cannot be used out of Maple.
As examples we used a couple of leaf types: Maple, Oak, and Pothos. Linear coefficients describing similarity of individual leaves are shown in the following table.
It is evident that leaves of the same variety are the most similar each to other. Similarity depends on leaf segmentation, of course
The algorithms were derived in the program Maple 7, running on the computer Autocont, PIV, 512 MB RAM
5. 2. 2002