Optimizing the Maximal Perturbation in Point Sets while Preserving the Order Type

Recently a new kind of fiducial marker based on order type (OT) has been proposed. Using OT one can unequivocally identify a set of points through its triples of point orientation, and therefore, there is no need to use metric information. These proposed order type tags (OTTs) are invariant under a projective transformation which allows identification of them directly from a photograph. The magnitude of noise in the point positions that a set of points can support without changing its OT, is named the maximal perturbation (MP) value. This value represents the maximal displacement that any point in the set can have in any direction without changing the triplet’s orientation in the set. A higher value of the MP makes an OTT instance more robust to perturbations in the points positions. In this paper, we address the problem of how to improve the MP value for sets of points. We optimize “by hand” the MP for all the 16 subsets of points in the set of OTs composed of six points, and we also propose a general algorithm to optimize all the sets of OTs composed of six, seven, and eight points. Finally, we show several OTTs with improved MP values, and their use in an augmented reality application.


Introduction
Fiducial tags, or fiducial markers, are used in computer vision (CV) applications for robot localization [1,2], mapping and localization of large environments [3][4][5], or for pose estimation in medical endoscopy [6]. Markers are also used for metric purposes, e.g., for calibration [7] and monitoring changes in distances and orientations in historic structures [8]. AprilTags [9] and Aruco [10] are perhaps the more used fiducial tags. Essentially, a fiducial marker is used in a CV application as pattern for a quick and easy detection by a computer, The position and pose of the fiducial marker with respect to a viewing digital cameras can be obtained automatically by the computer.
In this work we focus on a new kind of tags based on order type (OT) [11,12], called order type tags (OTTs), which are projective invariant and are also suitable for automatic identification and pose estimation [13]. These markers are composed of a typical black square frame with an inner white square and with black triangles inside of this last white square. Four examples of these OTTs are shown in Figure 1. The position of the triangle vertices form the set of points from which is possible to calculate its associated OT. This OT also forms a unique identifier for each OTT.
The scenario for the identification task is the following: An OTT instance is located in a scene, one image is generated through the camera sensor by targeting the camera to the scene in some position and orientation, in which the visual fiducial marker is visible in the resulting image. The obtained image is processed, i.e., the image is analyzed to identify the region in which the tag is visible to compute or to estimate the positions of the triangle vertices. These positions of the triangle vertices are taken as the elements to form a set of points, and from this set of points its OT can be calculated.  Figure 1. Four examples of order type tags (OTTS). The labels represent the subset number within the set C 6 (it is the set of all possible OTs formed with six points) in the database in [14]. More details about this notation will be given in the following sections of this work.
In [11] the authors use the point sets publicly available in [15] to build the OTTs. These data sets have already an associated maximal perturbation (MP): For a given set of points the MP is the maximal displacement (noise) that can be added to all the point positions without changing its OT. In this work we study how to optimize the MP for all the data sets in [15] with six, seven, and eight point elements.
With the optimized set of points, more robust OTTs can be built.
The contribution of this work is to analyze the problem of how to maximize the MP for a set of points. We provide a general algorithm to increase the MP for a set of points. Although the problem of finding the point positions within a set that maximizes its MP appears to be an easy geometrical problem, it is not; we can only provide approximated solutions. The exact solution is still an open problem.
This paper is structured as follows: Section 2 explains the maximal perturbation definition and the algorithm to compute it. Section 3 explains the optimization of MP by hand with sets of five points. In Section 4 we present a general algorithm to optimize the MP. In Section 5 the results of this algorithm to optimize C 6 , C 7 , and C 8 will be given. In Section 6 we present a discussion, and finally in Section 7 conclusions of this work are drawn.

Order Type and Maximal Perturbation
OT is a concept from the computation geometry field, it was originally proposed by [16] and it can be seen as a way to describe sets of points based on the orientation of subsets of three points (triplets). The OT concept is valid in any dimension but in this work we will work in two dimensions, with 2D points on a plane. Formally the OT is represented with a so-called λ-matrix [16]: Each of its entries λ i,j , for i, j = {1, 2, . . . n}, i = j, and n points in a set, represent the number of points in the set that are on the left side of the oriented line through points p i p j , for i = j.
This number of orientations for all the triplets of points can be calculated by counting the k positive double area of triangles formed by points p k p i p j , with k = i = j, and k, i, j ∈ {1, 2, . . . n}.
In this way, the λ-matrix for the example in Figure 2 is: The entries in the lower triangular λ-matrix have values λ j,i = n − 2 − λ i,j , thus only the values of the lower triangular λ-matrix, or the upper triangular λ-matrix, are independent and necessary to store a λ-matrix. Therefore only n 2 /2 − n memory locations are necessary to store a λ-matrix.
For two point sets A and B in a plane, where B is the translated, rotated and/or projected version of A into another plane, both sets will have the same OT. This property can be used to match the point correspondences in the two sets as in [13], and then to find the camera pose (position and orientation).
Authors in [15] analyzed all possible OTs that can be generated with sets from three up to 11 points, and those authors also provided a publicly available database [14] which contains all the possible OTs. In their database, point positions are represented with 8 bits (1 byte) up to cardinality 8. They use this binary format to store all OT instances to reduce the size of the database.
For a set of n points, n! different λ-matrices can be built, depending of how the points are labeled. Although these λ-matrices can be different, the associated OTs are not. One could select a specific λ-matrix that could help to identify the set, for example, their minimum lexicographically. In this way, the λ-matrix is one of the possibles forms to represent the OT. Another form to visualize the OT is that a λ-matrix can be built for a set of points; if the labels of the points change, the entries of the new λ-matrix will be permutations of the entries in the original built λ-matrix. Different point configurations must have different λ-matrices. All those different configurations are finite and were investigated by [15], and they are publicly available in internet [14].
There exists a single OT with three points and this forms a triangle. With four points there exists two OTs, one forms a square, and the other one forms a triangle with a point inside. With five points there exists three OTs. The set of all subsets of n points with different OTs will be represented as C n . C n i will represent the subset (an instance) i in C n with n points, C n i ⊂ C n . We maintain the same the order for the subsets given by [15] in their database [14].
Given a set of points, its MP value is the maximal displacement that any and all the points can have safely without changing the original OT. Let C represent any set of points, the maximal perturbation is defined as the half of the minimal distance from any point p i ∈ C to any line defined by a pair of points p j p k in C with i = j = k. In Figure 2 the MP concept is illustrated with one example: five points are drawn in a plane, the radius of the bigger circle represents the minimal distance in any point to a line, and for this example is from point p 3 to line p 1 p 2 ; the radius of the smaller circle is the MP, any point can be inside its respective smaller circle and the respective OT is kept. If points p 2 and p 3 , or points p 3 and p 1 , simultaneously cross the dashed line, the OT changes: The figure will be an irregular pentagon instead of a square with one point inside. In the next section, it will be optimized the MP "by hand" for every OT instance in the set C 6 , and in the Section 4 an algorithm to optimize C 6 to C 8 will be explained.

Optimizing MP for C 6
We try to analyze first how to optimize the subsets of points in C 6 (with six points). We have a grid of 256 × 256 to position every point, because 8 bits were used to store every number that represents those point positions. In general, a greedy strategy is performed with the following steps: 1. Fix the points belonging to the convex hull on the grid border. 2. Position the rest of the points inside an area proportional to the number of them. 3. The points are positioned optimally. In one have four points and three of them form a triangle, that is also its convex hull, the optimal position of the fourth is in the triangle's incenter: the intersection of the three internal angle bisectors. The incenter is at equal distances from the three triangle's edges. 4. The positions are refined by a partial exhaustive search, trying to move other points not involved directly in the MP calculation.
For instance, the optimal position of point p 3 in Figure 2 is in the center formed by p 1 , p 2 , and the intersection point of line segments p 1 p 4 and p 2 p 5 . Also, it is possible to increase the area of the referred triangle moving points p 4 or p 5 ; increasing the area of this triangle increases also the associated MP for the whole set of points.
The sixteen instances (or subsets) of C 6 are shown in Figure 3. Each one is numbered row by row (the first one in the upper corner at the left) and the number of points in their convex hull is in Table 1. The instances 1, 2, 3, 8, 9, and 10, which have 6, 5, 5, 5, 4, and 4 points in the convex hull, respectively, are trivial to optimize because of their symmetry in the convex hull points. The easiest instance is 1 because it has all its points form its convex hull, the resulted instance can be seen in Figure 4.  [14] and [15]. For the rest of the instances, each one is optimized with the aim of a different python script. The optimization procedure will be explained with one example. The instance chosen to optimize will be the fourth, it has four points in its convex hull. These four points are situated in the outer vertices of the grid, as shown in Figure 5. The point p 3 is positioned in the center of triangle p a p b p 2 (see Figure 5). The last point p 4 is positioned in the incenter of triangle p 3 p d p c . Point p c is calculated as the intersection of line segments p 1 p 5 and p 2 p 3 . Point p d is calculated as the intersection of line segments p 1 p 5 and p 6 p 3 . Clearly, this greedy strategy gives a small MP value (check Figure 5). Now MP can be improved if point p 3 is moved on the line p 3 p b . At each position on this line, the MP is recalculated at the final positions in Figure 4 is at the maximum MP value. Note that it is not the MP's global maximum. The obtained maximum MP is a local maximum. The procedure explained here is an heuristic that get good MP values-and very useful point positions-but it is not a procedure that obtains the best point positions that guarantee the MP's global maximum.
We give another example, the optimization of point subset C 6 5 . The points p 1 , p 2 , p 3 , and p 6 (equal to (0, 0), (255, 0), (255, 255), and (0, 255), respectively) are situated in the corners of the grid, as is shown in Figure 6 at the left. Point p 5 will in the incenter of triangle p 6 p a p f , where p a = (127, 127) and p f = (127, 255), thus p 5 = (90, 218). The next point p 4 , calculated in a greedy step, will be in the center of triangle p 5 p e p 3 , where point e is in the intersection of lines p 5 p 2 and p 1 p 3 , thus p 4 = (149, 196), with this set of points its MP value is equal to 0.63, which is very small, less than 1 unit. Instead we search for a greater MP value, with the aim of another python script, where p 5 = (90, y) and p 4 = (255 − 90, y), and y takes the values from the point c to b, as it is shown in Figure 6 at the right. In this way, points are symmetric with respect to the middle vertical axis, and this configuration does not change its order type. The optimized p 5 and p 4 are (90, 199) and (165, 199), respectively, and the MP value for the subset is equal to 12.50.  A summary of the results is shown in Table 1. The higher improvements in the MP are in the easiest instances. All python scripts are publicly available (http://cs.cinvestav.mx/~fraga/OptMP.tar.gz).
We called an optimization "by hand" of these instances of C 6 because we were unable to generate an algorithm to calculate the initial point positions given some of the points already in the border of the grid. Here the positions are set by carefully observing the point positions in the corresponding database in [14], which are the positions that define each OT.

General Algorithm to Optimize the MP
In this section, we present our approach to automatically modify the positions of the points for a given set of points C 1 , with a MP(C 1 ) value, to a new set of points C 2 with an associated MP(C 2 ) value higher or equal than the original, in such a way that the OTs of both sets are maintained unchanged, i.e., MP(C 2 ) ≥ MP(C 1 ) and λ(C 2 ) = λ(C 1 ).
We were able to optimize by hand the 16 instances in C 6 , but for C 7 and C 8 there are 135 and 3315 instances, respectively. Performing the optimization by hand for these two sets is not possible and for this reason an automatic approach is proposed.
We exploit the MP definition to iteratively modify each point position, without changing the OT. By moving each point belonging to each subset of points in such way that the OT is not changed or increased, the associated OT to that subset of points does not change. The idea is to take a point p i in the set, and try to find a new position, within its neighborhood, in such a way that the current MP is increased. If a new point position that enhances the MP is found, or at least the current MP value is not reduced, the new position is accepted. This process is repeated for all the points. The search space is discrete, and both point coordinates can have integer positions from 0 up to 255 (1 byte, as the original representation in [14]). Thus, the coordinates (x, y) for a point are attempted to be moved to their eight neighborhood positions {(x − 1, y + 1), (x, y + 1)(x + 1, y + 1)(x − 1, y)(x + 1, y)(x − 1, y − 1)(x, y − 1)(x + 1, y − 1)}. We detail this idea in Algorithm 1.
The input in Algorithm 1 is an instance l of C k l , that is, a set of k pairs of coordinate values (x, y), Then, for each point p i , for i = {1, 2, . . . , k}, each one of its eight neighborhoods {q} = N(p i ) will be analyzed, to search for the one that increases the MP value. To perform the search, the trial set C trial is used, which is a copy of input set C k l with a moved point. A trial set substitutes the previous one only if the moved point increases the distance to its closest line d trial , or remains unchanged. The procedure is repeated until no more changes in the point positions can be performed, or until a maximum number of iterations is reached. for all p i ∈ C new do 6: Obtain the eight neighbors {q k } = N(p i ).

7:
Compute the distance d current from p i to the closest line in C new 8: Compute mp ← MP(C new ) 9: p new ← p i A new point is initialized 10: for each neighbor q ∈ {q k } do 11: C trial ← C new 12: C trial .p i ← q Replace p i by q in C trial 13: Compute the distance d trial from q to the closest line in C trial 14: if MP(C trial ) ≥mp and d trial ≥ d current then 15: The complexity of Algorithm 1 is linear with respect to the number of iterations. The number of iterations can be considered unknown. The number of pixel neighbors to each pixel is constant, equal to 8. The number of points is a small number, in this study, a number in the set {6, 7, 8}. And the number of iterations is a number much bigger than the number of points.
We can not visualize a brute force approach to solve this problem. The MP value for a set of points with a fixed OT depends of the positions of the whole set. The idea of Algorithm 1 is to try to move all points and not a single one in each iteration. Also the positions of the points in the convex hull are certainly arbitrary, many of them can be tried.

MP
Optimization Results for C 6 , C 7 , and C 8 Algorithm 1 was applied to all the subsets of points in C k , for k = {6, 7, 8}, in [14] with a maximum number of iterations equal to 200. The results are shown in Table 2 and in Figure 7. In Table 2 the number of subsets that have a given MP value are counted, and these subsets are now represented with the set D n (v) which contains all the subsets with a MP lesser or equal to v. The improvement can be seen in the last row: for D 8 (9.0) there are now 60 optimized OTs with a MP greater than 9, when initially were only three. For D 7 (9.0), the number of subsets with MP greater than 9 increases from three to 33. We can observe a significant increase in the MP values: After applying our approach, OT instances that support a greater magnitude of noise are obtained. In Table 2, in the initial values on the left, we can observe the number of OT instances that support the given noise of magnitude in the first column. On the right, where we show the final results, we observe a clear improvement, i.e., most sets of points in C k increased their MP value, which increases the D k sets. Figure 7 presents these results from another perspective, as histograms of the number of OT instances within certain ranges of MP values for the sets C 6 , C 7 , and C 8 . Each subfigure shows a comparison of the initial MPs in the database in [14] and the results after applying the proposed algorithm to optimize their MP value. The four histogram comparisons clearly show an improvement of MP values. All sets of points with high MP values are increased. This case is especially notorious in Figure 7c, where we can observe that more than 2500 OT instances have their MP between 1 and 2 units. After our approach, we observe a new distribution of the bars in which the number of OTs with the same MP range is reduced to around 800, and the rest of MP ranges have a higher number of OT instances. For set C 6 a slight improvement was obtained with the procedure described in Section 3, in comparison with results shown in Table 2: All 16 instances have an MP value greater than 7.0 in Table 1 and in Table 2, 15 of them have a MP value greater than 7.0.
The results in Table 2 and Figure 7 clearly show that our designed Algorithm 1 automatically improves the MP for all instances in C 6 , C 7 , and C 8 , and is working correctly. After applying our algorithm to the original data in [15], it improved the positions for all the subsets of points, increasing their associated MP.
Two instances of the initial and resulting sets of points are shown in each row in Figure 8. In this figure, the left column shows the initial set of points and their associated MP value, the column at the right shows the obtained results in the last iteration of our approach, and their associated MP value.
In Figure 9 we can compare the OTTs made with the C 6 5 and C 6 9 subsets before and after the optimization by hand, as explained in Section 3. These two markers without their optimized point positions were shown previously in Figure 1. The markers are detected first in the input image as the black object with four corners; then, for the markers without optimize (in the left column of Figure 9), the black triangles inside the white zone are extracted. For the optimized markers built with C 6 5 and C 6 9 , these set of points have a convex hull that is also a square, thus the white zone was eliminated and white triangles are used instead. The elimination of this white zone (see the markers in the second column of Figure 9) increases the area cover by the optimized C 6 5 and C 6 9 set of points. A bigger area makes these optimized markers easier to recognize at farther distances.
Finally, an augmented reality application that use these two optimized OTTs is shown in Figure 10: Above each marker is drawn a virtual object. The point positions are calculated as the vertices of the black square and the vertices of the two white triangles. The extraction is made as follows: (1) A binarization is applied to the input image, (2) all the black components are labeled. For each black component in the image: (3) the perimeter is calculated, (4) the position of the first pixel in the perimeter is a vertex, (5) the position of the farthest pixel in the perimeter to the first vertex found, is the second vertex, and (6) the other two vertices are calculated as the positions of the two farthest pixels to the line that joins the two first vertices found. A similar process is made to calculate the three triangle vertices. These rough vertices positions are enough to calculate the match with the point positions of the marker model using the λ-matrices. To calculate the marker pose we use homography, and then it is necessary to refine the vertices positions to a subpixel precision by extracting the points among each pair of vertices, fitting a line with those points, and calculating the intersection point for each two lines. In Figure 10, each virtual object can be moved interactively when the respective OTT is also moved. This application uses the Qt and OpenGL libraries. OTT with C 6 5 not optimized OTT with the optimized C 6 5 OTT with C 6 9 not optimized OTT with the optimized C 6 9 Figure 9. Two examples of order type tags (OTTs) built with the subsets of points C 6 5 and C 6 9 without the original point positions in the database in [14], and with the corresponding optimized point positions by hand. Figure 10. A picture of an augmented reality application that shows two virtual objects drawn above the optimized markers C 6 5 and C 6 9 . These markers are also shown at the right of Figure 9.

Discussion
According to the results presented in Sections 3 and 4, we were able to improve the MP value for most of the processed OT instances. The improvement is very noticeable in histograms in Figure 7. In the comparison of histograms, we increased the number of OT instances with higher MP values, and also we reduced the number of OT instances with small MP values.
The MP value is only defined by the distance of the point to the closest line (defined by each pair of points) in the entire set of points. Although we are only analyzing one point and its distance to the closest line, in turn, this distance will define the current MP for the whole set of points. This is because the MP depends on only three points from the whole set of points. We could call these three points the critical points. In this sense, we could think that there is no reason for caring about displacing critical points that do not directly define the OT. Nevertheless, in some situations, the displacements of the non-critical points is necessary to allow future possible displacements for the critical points. For instance, consider a case with four points, these form an equilateral triangle and the fifth located at the center of the triangle. In that OT instance, the MP(C) depends on the distance of the central point to any of the three lines of the triangle. In a case like that, we see that we can not perform any movement on the central point without reducing the MP value. In order to make possible a movement in the central point that improves the MP value of the set, we first should move some of the points that form the triangle. With a movement of one or more of those points that define the external triangle we could make some space in such a manner that, in a subsequent search of a new location for the central point, we can find a new location that improves the MP for the set. This is exactly how our approach works. The algorithm tries to increase the distance of every point to its closest line, to try to expand the set of points in such a way that the critical points could be moved to new positions that improve the MP.
Optimizing by hand instances with more than six points is difficult. However, we can position the convex hull points on the marker corners. It could be very interesting to optimize by hand the instances in C 7 as those have four points in the same maker corners, and the other three points form a single triangle, and so its detection process will be simpler. We left this idea as a future work. It could be possible to fix the four points in the convex hull to the grid corners, and optimize the rest of the points with our proposed algorithm. In such a case, it will be necessary to carefully analyze by hand the initial point positions, which also define the associated order type for the set of points.
Also left as future work, is the analysis for an algorithm to calculate or to search the global optimum MP for a given set of n points. To find the point positions that correspond to the global optimum MP is still an open problem.

Conclusions
We analyze how MP can be optimized in the set C 6 , with six points. We also propose a general algorithm to improve the MP for C 7 , C 8 , and C 9 . The proposed algorithm performs one single distance point displacement at each iteration, based on the definition of the MP, which states that we can move any point in a set C to a new location without changing its OT if this movement is smaller than MP(C). We showed that our approach improves most of the OT instances of the database provided by [15]. The proposed approach improves the set of points in terms of the MP value, and thus it improves the performance for the markers based on OT, as these can resist more noise when their point positions are detected in an image. We show the use of these OT markers in an augmented reality application.