THE “BETA-SHAPE” ALGORITHM FOR POLYGONAL CONTOUR
RECONSTRUCTION
Costin-Anton Boiangiu
Department of Computer Science
“Politehnica” University of Bucharest
Abstract: An important problem in many Multimedia/Graphical applications is to
reconstruct as precise as possible a polygonal contour that bounds a given set of input
points. The basic scenario is as following: is considered a set of planar points placed in
a certain area and is needed to construct a polygon that encapsulates inside it all the
input points and reproduce as fairly as possible the area shape. The main usage of this
polygon is to detach/clip the inside polygon area from the plane, or to separate multiple
areas by non-overlapping polygons.
Keywords: alpha-shape, beta-shape, convex hull, tight fitting, contour
1. INTRODUCTION
There are several theories and techniques used to
solve the tight-fitting polygonal contours generation
for set of points defined in a certain space
(Edelsbrunner, 1987). One of the most efficient and
maybe one of the most used of them is the theory of
“Alpha-Shapes”. For a best understanding about what
the concept of “Alpha-Shapes” is referring to, let’s
consider a very simple and intuitive example: let us
imagine that all of the input points in the plane are
the heads of some nails fitted into a wooden panel in
the same relative positions as the points are in the
plane. Let also consider a ball of radius R that is
rolling onto the exterior of the “nailed surface” over
the nails. The ball must keep all the time the same
rolling direction, let’s suppose the direction is
clockwise-oriented. It is obvious that the ball will
enter between nails that are positioned at a distance
d R . On the other hand the ball will keep
rolling onto the nails at a distance d R . After the
ball has performed a full rotation, and reached the
initial position of the starting nail, let’s mark the nail
heads “touched” by the ball in the full-rotation
process. They will form a polygon non-selfintersected, oriented clockwise (as previously
supposed). This polygon is the R -Radius “AlphaShape” for the given input set of points.
The previous description of the “Alpha-Shape”
concept can lead us now to some computing
techniques that will help constructing it. Most of the
algorithms that compute “alpha-shapes” for a set of
points are based onto the Delaunay (Aurenhammer,
1991; Su and Drysdale, 1995; Guibas, et al., 1995)
triangulation process, an elegant but not very
economical approach. Also, it is easy to imagine
some of the disadvantages of this theory: points in
the plane cannot be controlled with respect to the
distances between them. For this reason, the “alphashape” of a small radius can build a polygon that
does not contain all the input points. On the other
hand, if the radius is big enough to ensure only one
output polygon, the “alpha-shape” may not reproduce
the contour very accurate and the output result will
be a coarse polygon, practically unusable most of the
times for a demanding multimedia application.
2. MOTIVATION
The evaluation of possibilities to construct polygonal
contours that approximates sets of points started
some time ago (Boiangiu, 2002a, b) with the
developing of an application that must separate the
various items belonging to a written page provided as
input (and usually the result of a scanned document).
The written page can contain elements like normal
texts, headings, pictures, picture texts (and possibly
other types) that are detected by the application. The
goal was to separate these items as precise as
possible using tight-fitting contours that avoid
overlaps between them in order to successfully
execute selective clipping from the page.
Since the distances between adjacent items and
between the elements that compose the items (like
text characters) are not controllable and is needed
only one shape that bounds every item, the usage of
“alpha-shapes” was not an option. As a result, was
started the developing of another algorithm that
always creates only one shape for an input set of
points and has a controllable behavior for the
tightness of the resulted polygon. The resulted
concept was named “Beta-Shape” and also a robust
algorithm to compute it was found.
both as tightness of the shape and as execution time
(the execution can always be stopped when feeling
confident that the result is refined enough for the
application purposes). It also chooses candidates to
be inserted in the “Beta-Shape” in a way that allows
uniform smoothing of the contour and avoid selfintersections. For this reasons every iteration step is
in fact a usable output polygonal contour that verifies
all the conditions needed by an application.
3. ALGORITHM OUTLINE
The input of the algorithm is an arbitrary collection
of planar points like in figure 1 defined by their
( x, y) coordinates:
Fig. 2. The convex hull of the input dataset
Fig. 1. The input dataset of the “Beta-Shape”
The used approach is to refine by successive
iterations the convex hull of the points. As a result,
the computing of the convex hull is the first step of
the algorithm. Since the convex hull can be defined
for any set of input points and can be computed by
some well-known and robust algorithms (Avis and
Bremner, 1995; Barber, et al., 1993), there is no need
to further analyze this step. What is important to
observe is that the convex hull contains all the input
points inside it and is the starting “Beta-Shape”
polygon that will be successively refined.
For the set of points presented in figure 1, the
resulting convex hull ABCDE (and the initial “BetaShape”) is presented in figure 2.
The input points that are not part of the convex hull
are called candidate points or simple candidates. The
algorithm specifies a way to insert candidates into the
“Beta-Shape” to refine it and to preserve the
precondition that it contains all the input points at
every refining step. The algorithm is controllable
For constructing the “Beta-Shape” a distance
parameter (named d ) is required. It is somehow
equivalent with the R parameter used in the
description of the “Alpha-Shape”. If two adjacent
points from the constructed shape in a certain
moment are placed at a distance lower than d then
the segment will be finally integrated into the “BetaShape” and will suffer no further refinements.
Otherwise, the process of successive refinements will
continue to try splitting the segment by finding the
best candidate for it and inserting it into the chain of
points.
In figure 3 the gray-bounded area is the range where
the algorithm searches for the best candidate that
matches the selection criteria to be inserted into the
polygonal chain. The convex hull denoted ABCDE is
processed by refinements beginning with the AB
segment. The candidate search area for the AB
segment is a square sharing one edge with the
segment and oriented towards inside the polygon. If
no successful candidate is to be found in this area
then all of the remaining candidates are taken into
account. For a good search process the algorithm
uses square areas because this search mode does not
encourage the usage of potentially better candidates
for other edges and restricts the search to a much
lower subset of the input dataset.
The points suffixed by 1 are the best candidates in
the step 1 for the corresponding edges. In the case of
edge AB the best candidate is A1, for the edge BC
the best candidate is B1, for CD is C1, for DE is D1
and for EA is E1. But what is the meaning of “best
candidate” for an edge? If one candidate is closer to
that edge than any other candidates and the insertion
of that candidate in the polygonal chain does not
generate self-intersections then it is the best
candidate for that edge. Why choosing the candidate
at the lowest distance? If a candidate has the lowest
distance then it would leave all the other points in the
input dataset inside the polygonal “Beta-Shape”
contour.
a y 2 y1
b x1 x 2
(2)
c a x1 b y1
The parameters for the edges that are perpendiculars
onto P1 P2 are:
a1 a 2 b
b1 b2 a
c1 b x1 a y1
(3)
c 2 b x 2 a y 2
Taking into account the results from equations (2)(3)
and assuming a clockwise orientation of the convex
hull resulted polygon (the orientation of the polygon
cannot change after any refinement that has been
applied) then the conditions for a valid candidate are:
b x a y c1 0
b x a y c 2 0
a x b y c EdgeLength
(4)
a x b y c 0
Fig. 3. The search area for an edge
The necessary verifications that a point is inside the
search area are very easy to perform in practically the
same step. There is only needed to compute the
a, b, c elements that define the line support for the
edge to refine: a x b y c 0 . This is very
easy because the coordinates ( x, y ) for the two
endpoints of the line, let’s denote them P1 ( x1 , y1 )
and P2 ( x2 , y 2 ) , are known. Now, it is possible to
express the line passing through two points formula:
x x1
y y1
x2 x1 y 2 y1
(1)
Where the first two conditions regards the placement
of the point ( x, y ) inside the two perpendicular
axes, the third condition means that the “depth” of
the point is lower than the edge length (square search
area) and the forth condition is in fact a precondition
that must be verified for all the points in the search
dataset to be sure that the correct polygon orientation
is maintained and that all of them are inside the
“Beta-Shape” at any moment.
This specific search mode inside a square area
defined by the current edge allows a good trade
between speed and quality of the output polygon.
Also it makes use of the input data locality and thus
enabling an application to fast-recover the search
point domain by using a simple two-dimensional
hash-table.
Grouping the terms in equation (1) by x, y there are
the following expressions for a, b, c :
The coordinates of the resulted bounding rectangle used as input for the two-dimensional hash-table
Relation between input points: P1 ( x1 , y1 ) and P2 ( x2 , y 2 )
Bounding Rectangle
XMin
XMax
YMin
YMax
x1 x2
y1 y 2
y1 y 2
x1 y 2 y1
x1
x
2
y
2 y1
x2
y1
y2
y 2 x2 x1 y1 x2 x1
x1 x2
y1 y 2
y1 y 2
x2 y 2 y1
x2
x
1
y
2 y1
x1
y1 x2 x1 y 2 x2 x1
y1
y2
Based on the previous ideas, the algorithm searches
the best candidate for every edge and marks this
candidate for inserting into that edge. This cycle must
be performed until all edges have potential
candidates or there are no more left candidates. With
the distances already computed in the previous step,
the algorithm chooses the distances in ascending
order. It merges the candidates (denoted A1, B1, C1,
D1, E1 in the example) into the “Beta-Shape” chain.
Every chosen candidate does not generate selfintersections so they can be safely inserted. The
result is represented in figure 4.
for time deviations. There were performed 1000 time
measures.
Fig. 5. Results of the “Beta-Shape”
Fig. 4. The “Beta-Shape” after first cycle
The algorithm continues with new search areas (graybounded in figure 4) and new best-candidate retrieval
until there are no more candidates left, any chosen
candidate generates self-intersection (internal status
of “deadlock”) or all the edges have lengths lower
than d .
Fig. 6. “Beta-Shape” construction algorithm execution time
vs. dataset input size
4. RESULTS
The algorithm was implemented and tested with the
main goal of proving its robustness and to make
various performance measurements. The figure 5
presents a result of the constructing “Beta-Shape”
associated with a set of images from a newspaperscanned page. A call to the algorithm was made
using an input containing filtered points belonging to
a section of the image consisting from the picture of
the football player and the center-right picture.
The
“Beta-Shape”
algorithm
has
a
variable
5
2
complexity of about O(n ) for random input data
3
sets and a much better complexity of about O(n 2 ) for
data sets generated from real images. The figures 6
and 7 presents some statistics about how the input
time is affected by the number of points presented in
the input dataset. The results are plotted in the graphs
without performing an average, to enable measuring
Fig. 7. Complexity of “Beta-Shape” construction algorithm
for random input dataset
5. CONCLUSION
The “Beta-Shape” algorithm:
Can be controlled as time vs. refinement
quality using the d parameter.
Is robust and generates a single output
polygon for any input dataset.
At every step the intermediate result is fully
valid so that it is possible to trade between
execution time and refinement quality and to
stop whenever the output polygon satisfy
application needs and/or the allocated time
for refining was consumed.
5
Has a variable complexity of about O(n 2 )
for random input data sets and a much better
3
complexity of about O(n 2 ) for data sets
generated from real images.
Does not need auxiliary memory in large
quantities. Practically all the needed
memory space is O(n) since the final
“Beta-Shape” is a subset of the input
dataset.
Has a clear end since every step performed
consumes at least one candidate from the
input dataset.
The convex-hull points are always among
the points contained in the output polygon.
Can be easily adapted for the 3-dimensional
(and even for the n-dimensional) case since
there are only used concepts like convexhull (Barber, et al., 1993; Dwyer, et al.,
1987) and space separation equations (Lee
and Schachter, 1980) that in 2-dimensional
case are the line equations (4).
6. REFERENCES
Aurenhammer F. (1991) Voronoi diagrams - A
survey of a fundamental geometric data structure.
ACM Computing Survey, 23(3), 345-405.
Avis D. and D. Bremner (1995) How good are
convex hull algorithms? In: Proceedings 11th A.C.M.
Symposium on Computational Geometry, pages 2028, Vancouver.
Barber C.B., D.P. Dobkin, and H. Huhdanpaa
(1993) The quickhull algorithm for convex hull.
Tech. Rep. GCG53-93, Geometry Center, University
of Minnesota.
Boiangiu C.A. (2002a) Tehnici Multimedia. Macarie,
„Universitaria” Collection.
Boiangiu C.A. (2002b) Elemente ale Realităţii
Virtuale. Macarie, „Universitaria” Collection.
Dwyer R.A. (1987) A faster divide and conquer
algorithm for constructing Delaunay triangulations.
Algorithmica, 2:137-151.
Edelsbrunner H. (1987) Algorithms in
Combinatorial Geometry. Springer-Verlag, Berlin.
Guibas L.J., D. E. Knuth, and M. Sharir (1990)
Randomized incremental construction of Delaunay
and Voronoy diagrams. In: Automata, Languages
and Programming, LNCS N.443, 414-431. SpringerVerlag.
Lee D.T. and B.J. Schachter (1980) Two algorithms
for constructing a Delaunay triangulation. Int. J. of
Computer and Information Science, 9(3), 219-242.
Su P. and R. L. S. Drysdale (1995) A comparison of
sequential Delaunay triangulation algorithms. In: 11th
ACM Computational Geometry Conf. Proc.
(Vancouver, Canada), ACM Press, 61-70.