Optimal Ellipse Based Algorithm as an Approximate and Robust Solution of Minimum Volume Covering Ellipse Problem

. We propose a algorithm to give a approximate solution of a minimal covering circle or ellipse of a set of points. The iterative algo-rithm is based on the optimal ellipse which best describe a given set of points.


Introduction
In order to more realistically simulate the behavior of solid in games, we have to check especially if they collide with each other every time they move, and if they do, we have to do something about it. This lead us to game physics engine that gives the game's world life. Understanding collision physics in 2D and 3D games [1][2][3] is particularly important for game developers. The collision detection algorithms depends on the type of shapes that can collide. We can consider e.g. rectangle to rectangle or circle to circle collisions. In general case we will have a simple generic shape that covers the entity known as a "hitbox" so even though collision may not be pixel perfect, it will look good enough and be performance across multiple entities.
This problem can be also reformulated as finding the unique minimum volume covering ellipse (MVCE) problem of finite set of points in N -dimensional real space (namely in IR N ) if we consider just elliptical generic shapes. Such an ellipse has appealing mathematical properties which makes it theoretically interesting and practically useful. This convex constrained problem arises in a variety of applied computational settings, particularly in data mining and robust statistics. For example in computational statistics, the minimum-volume ellipsoid covering k of m (0 ≤ k ≤ m, k, m ∈ IN) given points in IR N is well-known for its affine equivariance and positive breakdown properties as a multivariate location and scattering estimator [4]. In the area of robust statistics and data mining, efficiently finding outliers is a challenge that has attracted much research interest [5]. Indeed, one can identify data outliers quickly if one can compute the minimum-volume ellipsoid quickly, because outliers are essentially points on the boundary of the minimum-volume covering ellipsoid.
In this paper we focus on the image data, namely the points from IR N . The extended version for arbitrary dimension with streaming approach is prepared as a full paper and will be published in the future.
A new algorithm for finding the MVCE is based on the Mahalanobis distance [6] and uses the statistical and analytical properties of circular and elliptical objects, is proposed herein. The main advantage of the proposed method is that no complicated mathematical computation is involved in the implementation. Thus its evaluation is very fast. However the outcome ellipse is not optimal one -this will be disused in further part of this article.
We compare our algorithm with the incremental algorithm of Welzl, with move-to-front heuristic [7] -the whole implementation is described in [8].
The remainder of the paper is organized as follows: in the next section we present basics of the covariance matrix and Mahalanobis distance. In the third section we provide the algorithm for finding approximate minimal covering ellipse. The next section gives same experiments o illustrate the performance of our method. Finally, the last section contains some concluding remarks and possible directions of future work.

Covariance matrix and optimal ellipse
Multivariate and multidimensional analysis has been one of the most important areas in the modern statistics. Thus, the researchers have developed many useful techniques to efficiently describe the behavior of complicated data.
The definition of the covariance matrix states as follows, if set C is discrete, namely C = {x i } N i=1 ⊂ IR N , then the covariance matrix equals x i is a mean of set C. In the general case by the covariance matrix of a set we understand the covariance of the uniform normalized density on S.
Theoretically, covariance is the object which represents the true statistical independent structure of the underlying population units. On the other hand, if based solely on empirical data, only a small piece of the independent structure is obtained. It is therefore important to select the efficient representations of the data for sampling the covariance matrix. Remark 1. In practice the mean and the covariance matrix for a given set C ⊂ IR N is unknown. Thus they must be estimated from random variables (observed samples) by well-known estimatorŝ where x i ∈ C for i = 1, . . . , n and w i -the weight of the point x i . If all weights are the same, the weighted mean and covariance reduce to the sample mean and covariance. The weight assigned with the point of space will be used to store (and use) the information about color while the work is done with grayscale images. For a binary image a natural simplification is employed: 1 for the foreground color (usually black) and 0 for the background color (usually white).
Remark 2. The above consideration discuses discrete sets. In general case the basic definition of covariance matrix can be stated as follows. For a random variable with a probability density function f : IR N → IR the covariance matrix of set S ⊂ IR N can be computed 3 as where µ is an expected value (mean) of set S.

Pixels on image as a atomic piece of information in covariance matrix
When we apply the above investigations to image data, we shall threat a single pixel (point with coordinates ( is the size of the image) like a square. It allows to convert the discrete data of an image to continuous, which is more natural and consistent with the human perception of images. To calculate the measure of such transformation we use the following remark.
where I denotes the identity matrix. This can be used to compute the measure and covariance of S efficiently. 3 If the set S is discrete, namely S = {xi} N i=1 , then the covariance matrix equals In the case of the image data we set δ = 1, which is because the coordinates of each pixel are integers.
In general case we have to determine the appropriate value of δ, for which investigated dataset can be threated as a subset of δ · Z Z N .
This section is concluded with a simple, but important observation for singletons in image data, namely for X = {x 0 } we get where I denotes identity matrix and x 0 ∈ Z Z 2 .

An in-place covariance modification
Following theorem highlights how mean and covariance matrix will change if we add same points to the set, which will be used for the algorithm in the further part of this work. While new algorithm in each step modify mean and covariance matrix respectively to added point, this theorem allows as not to recalculate the whole covariance matrix each time -we just calculate the change of covariance matrix.

Mahalanobis distance
It is well-known that the Euclidean distance between two points x and y in real space is given by where T denotes the transpose operation and I is the identity matrix. It follows immediately that all points with the same distance from the origin x − 0 = c satisfy x 2 1 + . . . + x 2 n = c 2 , which means that all components of the observation x contribute equally to the Euclidean distance of x from the center.
However, in statistics variability (how the set is spread out or closely clustered) is also considered. If the correlation between variables is to be taken into account when computing statistical distance, then we use Mahalanobis distance, which can be defined as follows.
Definition 1 (Mahalanobis distance). Let C denote the given subset of IR N . By m C the mean value of C is denoted, and the covariance matrix of C is denoted by Σ C . The statistical distance or Mahalanobis distance between two points x, y ∈ IR N is defined as If y = 0 then the equation (3) is the general equation of an ellipsoid centered at the origin. In practice the center of the observations will differ from the origin, thus the distance from the mass center of observed samples chosen y = m C will be of interest.

Ellipse in Mahalanobis transformed space
A brief summary of the Mahalanobis distance and transform properties was given in previous section. Some important observations crucial in the construction of the following algorithm with the use of Mahalanobis distance will be hereby presented.
Recall the value of the Mahalanobis distance of the unit N -dimension ball receptively to covariance matrix Σ can be calculated, namely The following knowledge is crucial for the algorithm construction.

Theorem 2 ([10]
). Consider uniform probability density on the ellipse E ⊂ IR N with mean m E and covariance Σ E . Then Theorem 2 gives the equation for optimal ellipse for given set and has the following consequences in understanding of the elliptical pattern recognition. Moreover, it describe how to reconstruct the set if we just have mean and covariance matrix.
Remark 4. Theorem 2 gives the necessary and sufficient condition for a given shape to be elliptical (generalization of plane ellipse) -general ellipse in arbitrary dimension. Namely, it can be stated that an object E ⊂ IR N is an ellipse if and only if it can be approximated by B Σ E m E , √ N + 2 or, that is, The above considerations gives us the specified condition to decide whether or not the current point x from the cluster C ⊂ IR N belong to the "elliptical" part of the cluster. Namely, the condition for point x is given by where m C and Σ C denote the mean and covariance of C respectively. This gives as full necessarily information for construction the proper algorithm for finding approximate minimum volume covering ellipse.

The algorithm
In this section we introduce the algorithm for finding approximate minimum volume covering ellipse. We will describe this algorithm using Figure 1 which presents the example of investigated set (original image) and steps of the algorithm. Let consider the finite set C of which we want to calculate the smallest covering ellipse. Since C is finite we can state C = {x i } i=1,...,M . At the beginning of the algorithm we calculate the optimal ellipse for C, by calculating the mean and covariance matrix denoted m 0 and Σ 0 respectively. The optimal ellipse is current approximation of minimal covering ellipse.
Then in each i-step we proceed as follows: we check which of points in C are not covered by current approximation of minimal covering ellipse -we denote the set consist of such points by l i . If the set l i is empty we end the algorithm; we calculate the mean and covariance matrix for set l i and denoted them m i and Σ i respectively; we update the current approximation of minimal covering ellipse according Theorem 1; then we proceed to next step.
The pseudo-code of the algorithm can be stated as follows: Algorithm 1 Finding approximate minimum volume covering ellipse The outcome of this algorithm are the mean and covariance matrix of approximate covering ellipse.
The following comment are needed to clarify the algorithm statements and used notations: the m i and m li denotes the mean of current approximation of convex hull and the mean value of set l i respectively; the Σ i and Σ li denotes the covariance matrix of current approximation of convex hull and the covariance matrix value of set l i respectively; the condition x ∈ B Σi (m i , √ N + 2) means that for tested x we get calculation of m i+1 and Σ i+1 in each step are done according to equations (1) and (2) from Theorem 1.

The new algorithm in simple illustrations
Emo Welzl [7] proposed a simple randomized algorithm for the minimum covering circle problem that runs in expected O(N ) time, based on a linear programming algorithm of Raimund Seidel [11]. The algorithm is recursive, and takes as arguments two sets of points S and Q. The algorithm computes the smallest enclosing circle of the union of S and Q, as long as every point of Q is one of the boundary points of the eventual smallest enclosing circle. Thus, the original smallest enclosing circle problem can be solved by calling the algorithm with S equal to the set of points to be enclosed and Q equal to the empty set; as the algorithm calls itself recursively, it will enlarge the set Q passed into the recursive calls until it includes all the boundary points of the circle.
In this work we compare result of our new algorithm with the incremental algorithm of Welzl implemented in CGAL library [12]. The Figure 2 compares the results of finding smallest enclosing ellipse for same set of image data. As we can observe the results sames to be identical. However, the time needed to calculate those results differ for both algorithm -compare with Table 1. Thus our algorithm seem to be better in time consuming tests.
To confirm this we choose the benchmark image - Figure 3 -which has originally size 300 x 300 pixels and contains 8000 black pixels (points of interest). Then we resize the original image according to sizes given in Table 2. For each sizes we calculate the execution time of both algorithms.
This experiments shows that indeed the authors' algorithm is faster. However it seam that the complexity of new algorithm is also O(N ), but this complexity in this case is realized with smaller constance then in case of Welzl algorithm.

Conclusions
Int this paper the new approach for finding minimal covering ellipse was presented. This new method based on calculating the covariance matrix and interpret this according to behavior of Mahalanobis distance. The main advantage of this approach is that the results can be obtained very quickly.
We are planning to test this approach for streaming data, to detect the changes in stream data trends.