You are on page 1of 72

Technische Universität München

Computational Science and Engineering


(Int. Master’s Program)

Master’s Thesis
Development of Efficient Algorithm for
Geometrical Representation based on Arclet
Decomposition
Piyanut Pongpiyapaiboon

1st examiner: Prof. Dr. Thomas Huckle


2nd examiner: PD Dr. Hartmut Führ
Assistant advisors: Dr. Felix Friedrich, Dr. Laurent Demaret

Thesis handed in on: 10 November 2005


I hereby declare that this thesis is entirely the result of my own work except
where otherwise indicated. I have only used the resources given in the list of ref-
erences.

Munich, 10 November 2005

Piyanut Pongpiyapaiboon
Preface
The work presented was carried out at GSF - National Research Center for En-
vironment and Health (Institute of Biomathematics and Biometry ,IBB). It was
developed in the project ” Geometric multiscale image approximation schemes”
in the group of Mathematical Modelling in Ecology and the Biosciences led by
Prof. Dr. Gerhard Winkler and under the supervision of PD. Dr.Hartmut Fuerh.

I gratefully acknowledge Dr. Hartmut Fuehr for his inspiring guidance, valu-
able suggestions and patience. I particular would like to thank Dr. Felix Friedrich
for helping me with valuable suggestions and many ideas to work with Oberon
programing and for motivating me to do this thesis. I am especially indepted to
Dr. Laurent Demaret for mathematical inspiration, encouragement and patience.
I thank the members of GSF for thier support.

Many thanks to my friends , my host family in munich.

Piyanut Pongpiyapaiboon
Contents

1 Introduction 5
1.1 Dyadic Partition of the Image Domain . . . . . . . . . . . . . . . 6
1.2 Wedgelets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3 Arclets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4 Why consider arclets? . . . . . . . . . . . . . . . . . . . . . . . . 12
1.5 2-dimensional Potts-Functional
and its minimization . . . . . . . . . . . . . . . . . . . . . . . . 17

2 Digitization of the Arclet Scheme 19


2.1 Why consider the summation trick? . . . . . . . . . . . . . . . . 20
2.2 Summation over Continuous Domains . . . . . . . . . . . . . . . 21
2.3 Summation over discrete domains . . . . . . . . . . . . . . . . . 22
2.3.1 Algorithm to Traverse a Circle . . . . . . . . . . . . . . . 23
2.3.2 Cumulative sum computation . . . . . . . . . . . . . . . 27
2.3.3 Find minimum and maximum radius. . . . . . . . . . . . 30
2.3.4 Intersection of arcs with rectangle . . . . . . . . . . . . . 32
2.3.5 Ordering of the Intersection Points . . . . . . . . . . . . . 36
2.3.6 Determining the best arc split . . . . . . . . . . . . . . . 38
2.4 Painting an arc split . . . . . . . . . . . . . . . . . . . . . . . . . 40

3 Examples and Experiments 45


3.1 Oberon implementation . . . . . . . . . . . . . . . . . . . . . . . 45

Appendix: Original Images 65

4
Chapter 1

Introduction

This thesis is concerned with efficient algorithms for the segmentation of images,
using so-called ‘arclets’ for the modelling of geometrical fine structures in images.
We consider finite image domains S = {1, ..., 2n } × {1, ..., 2n }, and continu-
ous image domains S = [0, 1[2 . The precise choice will be made clear depending
on the context. An image is a map y : S 7−→ R. A segmentation consists of a
partition P of the image domain S into connected regions, and for each region
R ∈ P a function yR : R 7−→ R from a prescribed set of functions (local regres-
sion models). In this thesis, we choose the simplest local regression model, i.e.,
constant functions. So every segmentation consists of a partition P, and for each
p ∈ P, a constant function yp on p.
If we piece functions yp together then an approximation of function y is ob-
tained, denoted by yP . Hence, we are considering the problem of first partitioning
the image domain into connected regions and then approximating the image by a
constant on each single region. Criteria for a choice of segmentation are usually
given in the form of a variational problem, by minimization of a suitable func-
tional
H(y, (P, yP )) = U (P, yP ) + D(y, (P, yP ))
in (P, yP ), ranging over a certain prescribed set of segmentations. The D-term
measures the distance of segmentations (P, yP ) to image data y, and U is a regu-
larization term. In the suitable functional, U are contains information or assump-
tions about the original, and D contains assumptions about the noise.
One motivation for considering such a problem is denoising [2]: Here we as-
sume that the image y originated from an element of the segmentation by some
distortion or noise effect, and we want to recover the original image. Also, seg-
mentations can be used to directly extract information from the image, such as
edges.
There are two approaches for considering the minimization problems, stochas-
tic optimization methods ,see [8],[1], [18] and deterministic minimization in a

5
restricted search space. In this thesis we apply the deterministic approach, the
motivation behind this approach is to obtain efficient algorithms and exact min-
imizers. One example of such an approach are dyadic partitions, which have a
structure that allows fast minimization algorithms. Wedgelets were defined as a
refinement of dyadic partitions, and the arclets presented below will be a further
refinement.

1.1 Dyadic Partition of the Image Domain


In the following, partitions are defined for two dimensions. All partitions consid-
ered below are obtained by refining dyadic partitions.

Partition Let S be an image domain and R be a family of subsets of S. A finite


set P ⊂ R is called a partition of S if the following three conditions hold
S
(a1) S = p∈P p

(a2) r ∩ q = ∅ for r, q ∈ P and r 6= q.

(a3)All r ∈ P are connected (in the finite case, connected with respect
to four-neighborhoods.)

Dyadic Square If S = [0, 1[2 , a dyadic square p ⊂ S is a subset of the form


q = k2−j + [0, 2−j ), with j ≥ 0 and k ∈ {0, . . . , 2j − 1}.
If S = {1, ..., 2n } × {1, ..., 2n }, a dyadic square is a subset of the form
q = k2j + {1, . . . , 2j }2 , with 0 ≤ k < 2n−j .
A quad split of a dyadic square q is the set of the four next smaller dyadic
squares contained in q.

qsplit

Figure 1.1: Quad Split

6
Dyadic Partition A dyadic partition of the image domain S is given by any finite
partition Q of S into disjoint dyadic squares. Dyadic partitions are gener-
ated by recursively applying a quad split to the image domain. The tree
structure induced this way will be utilized in the development of a mini-
mization algorithm. We can establish the tree structure associated to this
decomposition. If Q = {p1 , ..., pn } is a quadtree partition then T be the set
of all dyadic squares containing at least one element of Q as a subset. Then
the inclusion of dyadic squares makes T a quadtree, and the leaves of T are
the elements in Q.

Figure 1.2: Quad-tree

1.2 Wedgelets
Let S = [0, 1[2 be the continuous image domain. Consider a rectangle Q ⊂ S, for
each point x ∈ R2 and angle α ∈ [0, 2π[, the sets Ax,α (Q) and Bx,α (Q) be defined

7
by

Ax,α (Q) = {(u1 , u2 ) ∈ Q : (u2 − x2 )cosα ≥ (u1 − x1 )sinα},


Bx,α (Q) = {(u1 , u2 ) ∈ Q : (u2 − x2 )cosα < (u1 − x1 )sinα}.

The sets Ax,α (Q) and Bx,α (Q) are disjoint, connected, and their union is the rect-
angle Q for each x ∈ R2 and α ∈ [0, 2π[.
A wedgelet partition P is obtained from a quadtree partition Q by splitting
each element q ∈ Q into (at most) two wedge-shaped sets along the straight line
with angle α, q = w1 ∪ w2 .

r
Lx,α

x
Rx,α

Figure 1.3: wedge division of rectangle

A wedgelet segmentation is a pair (g, W) consisting the wedge partition W


and function g that is constant on all w ∈ W

8
Figure 1.4: Wedgelet segmentation

9
1.3 Arclets
Wedgelets were introduced by Donoho [4]. Algorithms for the efficient imple-
mentation of wedgelets were developed in [16], [6]. The motivation of wedgelets
was to include edges that are not horizontal or diagonal. In this thesis we want to
extend this to arclets, which allows to include curved edges.
The aim is similar to the wedgelets, replacing straight lines by circular arcs:
We consider a quadtree partition of the image domain, and allow to split each
element of the partition along a circular arc.
Consider the continuous domain S = [0, 1[2 , a rectangle Q ⊂ S, a center point
xc = (xc,1 , xc,2 ∈ R2 , and a circle Cr centered around xc with radius r ∈ R+ .
The set Axc ,r and Bxc ,r be defined by

A(xc ,r) (Q) = {(u1 , u2 ) ∈ Q : r2 > (u1 − xc,1 )2 + (u2 − xc,2 )2 },


B(xc ,r) (Q) = {(u1 , u2 ) ∈ Q : r2 ≤ (u1 − xc,1 )2 + (u2 − xc,2 )2 },

the sets Axc ,r (Q) and Bxc ,r (Q) are disjoint, connected, and their union is the rect-
angle Q for each x ∈ R2 and r ∈ R.
An arclet partition P is obtained from a quadtree partition Q by splitting each
element q ∈ Q into (at most) two sets, along a suitable circular arc q = w1 ∪ w2

B(xc,r)

A(xc,r)

r
cr(xc,yc)

(xc,yc)

Figure 1.5: arclet with a rectangle.

10
A arclet segmentation is a pair (g, A) consisting of an arclet partition A and a
function g that is constant on all a ∈ A.

Figure 1.6: Arclet segmentation

11
1.4 Why consider arclets?
Geometrical representation based on arclet decomposition has been developed to
improve the performance of the wedge approach. In order to compare the different
approaches we use approximation rates for horizon images.
Horizon image Horizon images are a simple model for an image consisting of
homogeneous regions with smooth boundary. Let f : [0, 1[→ [0, 1[ be a
boundary function, and define y : [0, 1[2 7−→ {0, 1} where
½
1 if x2 ≤ f (x1 )
y(x1 , x2 ) =
0 otherwise

(x, f(x))

Figure 1.7: Horizon Image

Approximation rates Since we consider the problem of segmentation the image


domain as disjoint connected pieces and approximating it by a constant on
each segment, i.e. given a partition P , let yp denote the approximation as-
signing each x ∈ p ∈ P the mean value of y over p. The different schemes
(quadtree, wedgelet or arclet) determine different classes C of possible par-
titions used to approximate the image. For the purpose of comparing the
different schemes, we use the approximation rates for certain class of the
image.
Given a partition class C, let

εN (y) = inf ky − yp k ,
P ∈C,|P |≤N

12
i.e., the best possible approximation of y by a partition P ∈ C with at most
N pieces. We look for approximation schemes which give a fast decay
εN −→ 0, with faster decay for smooth boundaries.

Continuity properties of the boundary


The boundary function f : [0, 1[→ [0, 1[ is called uniformly continuous
⇐⇒ ∀² > 0, ∃δ > 0 such that |x − y| < δ ⇒ |y(x1 ) − f (x2 )| < ε

f ²C α ([0, 1[), for α ∈ (0, 1)


⇐⇒ ∃C > 0, |y(x1 ) − f (x2 )| ≤ C|x1 − x2 |α for ∀x1 , x2 ∈ [0, 1[
Finally, for n < α < n + 1, we write f ∈ C α ([0, 1[) if f is n−times
continuously differentiable, and f n ∈ C α−n ([0, 1[)

The aim of this section is to show that using more complicated schemes (wedgelets
instead of quadtree, arclets instead of wedgelets) results in better approximation
rates. The following arguments are not mathematically rigorous, and they are also
not complete, but they provide a certain motivation. First we need a statement
about how well a dyadic partition can adapt to a horizon image.

Covering the boundary by dyadic squares


Lemma1:Assume f ∈ C 1 ([0, 1[) and it derivative f 0 is bounded. Let graph(f ) =
{(x, f (x)) : x ∈ [0, 1[ } ⊂ [0, 1[2 . For j ≥ 1, let Dj (f ) = {q : dyadic squares
of size 2−j × 2−j : q∩ graph (f ) 6= ∅}. There exists a constant d > 0 such that
|Dj (f )| ≤ d · 2j
Moreover, there exists a dyadic partition Tj (f ) containing Dj (f ) with |Tj (f )| ≤
3d · 2j .
We can show the proof of above lemma by showing that there exists a constant
d, independent of j and k such that the number of elements in Dj (y) which are
above the interval Ij,k = [2−j k, 2−j (k + 1)[ is at most d, when j > 0, and 0 ≤
k ≤ 2j − 1. For this purpose, let x0 = 2−j (k + 12 ) and for ∀x ∈ [0, 1[ , the mean
value theorem states that f (x) − f (x0 ) = (x − x0 ) · f 0 (ξ) , ξ is between x, x0 and
therefore

|f (x) − f (x0 )| = |x − x0 | · |f 0 (ξ)|


≤ |x − x0 | · supξ0 ∈[0,1[ |f 0 (ξ0 )|
| {z }
=d0 <∞

Therefore if x ∈ Ij,k , |x − x0 | ≤ 2−j−1 then |y(x) − y(x0 )| ≤ 2−j−1 · d0 .


Hence,y(x) ∈ [y(x0 ) − 2−j−1 · d0 , y(x0 ) + 2−j−1 ] and the latter set is contained
in at most d0 dyadic intervals of the length of 2−j . This shows the statement about

13
Dj (f ). The trees Tj (f ) are obtained recursively: If Tj (f ) is given, Tj+1 (f ) is
found by applying a quad-split to all elements in Dj (f ). Hence Tj+1 (f ) has
3|Dj (f )| more squares than Tj+1 (f ), which shows that |Tj (f )| ≤ 3d · 2j .

Estimating the quadtree approximation error for horizon images


Let us establish the quadtree approximation rates for a horizon image. Given y, f
as defined in the horizon image definition, with f ∈ C 1 ([0, 1[) and f 0 bounded.
We fix j > 0 and consider the quadtree Tj (f ) obtained in the previous lemma.
This quadtree has at most N = 3 · C2j where in the constant case gives |Dj (y)| ≤
C · 2j . We define a quadtree approximation Gj which is constant on the elements
of Tj (f ).

Figure 1.8: Quadtree segmentation on a curve image

Each element q ∈ Tj (y) \ Dj (y) does not meet the boundary. On each such q
the image y is constant, and Gj takes the same value. For q ∈ Dj (f ), we let Gj
take the mean value of y. Then we obtain the squared approximation error
X
kY − Gj k22 = kY |q − Gj |q k22
q∈Tj
X
= kY |q − Gj |q k22
q∈Dj (y)

By construction, y − Gj = 0 , on all q ∈ Tj \ Dj (y)), hence only the elements of


Dj (y) contribute to the approximation error. For these we can estimate

14
Z
ky|q − Gj |q k22 = | y(x1 , x2 ) − Gj (x1 , x2 )|2 dx1 dx2 ≤ 2−2j
q | {z }
≤1

, as 2 is the area of q. Hence we have d·2j elements of Dj (y), each contributing


−2j

at most 2−j ×2−j which yields an overall estimate d·2−j . Therefore, for N = d·2j
we have an estimate εN (y) ≤ C · 2−j = O(N −1 ).
It can be shown that in general, a better approximation can not be obtained,
even if the boundary function is very smooth.

Estimating wedgelet approximation of horizon images


Let us now assume that the boundary function has regularity C α , with 1 < α < 2.
We first proceed as in the quadtree case: The tree Tj (f ) consists of N = 3d2j
dyadic squares. Only the elements of Dj (f ) have a nonzero contribution to the
approximation error.
The only way to improve over quadtrees therefore concerns the estimate of
ky|q − Gj |q k22 , for q ∈ Dj (y). This is done by a first order Taylor approximation
of the boundary function.
Let q ∈ Dj (y),

q = [2j k, ..., 2j (k + 1)[×[2j m, ..., 2j (m + 1)[


We denote x0 = 2−j · (k + 21 ) and then split q along the tangent at (x0 , f (x0 )),
i.e. along the line (x0 , f (x0 )) + (1, f 0 (x0 )).

f(x)

tangent

Z0

Figure 1.9:

Thus we define Gj on q as the function taking value ’one’ below the tangent
and ’zero’ above the tangent. We define Gj on Tj \ Dj (y) as we mention before.

15
We again obtain kY − Gj k22 as the sum of the square of approximation error con-
tributed by the elements of Dj (y). For each such q, the square of approximation
error is the area between the tangent and graph (y), which can be estimated by the
mean value theorem: For each x ∈ [0, 1[,

f (x) = f (x0 ) + (x − x0 )f 0 (ξx ) ,

for a suitable ξx between x and x0 . Therefore


Z 2−j(k+1)
|f (x) − f (x0 − (x − x0 )f 0 (x0 )| dx
2−jk
Z 2−j(k+1)
= |(x − x0 )f 0 (ξx ) − (x − x0 )f 0 (x0 )| dx
2−jk
Z 2−j(k+1)
= |x − x0 | |f 0 (ξx ) − f 0 (x0 )| dx
2−jk

The assumption f ∈ C α , hence |f 0 (ξx ) − f 0 (x0 )| ≤ |ξx − x0 |α−1 . Hence, we can


estimate the integral from above by d · |x − Z0 |α ≤ d · 2−αj and the integral by

d· 2−j
|{z} × −αj
2|{z}
length of integration domain upperboundforintegrand

Summing over all d · 2j elements, we obtain

kY − Gj k ≤ d · 2j · 2−j · 2−αj
= d · 2−αj ,

with N = d · 2j pieces. Hence, the wedgelet approximation rate is O(N −α ) for


1 < α < 2.

Estimating arclet approximation of horizon images


Now let the boundary function f ∈ C α , for 2 < α < 3. We repeat precisely
the same argument as for the wedgelet case. Here we need to show that for each
interval I = [2−j k, 2−j (k + 1)[, there exists a circular arc, such that the area
between the arc and the graph of f is less than or equal to C2−j−αj , with a constant
C independent of j and k. This can be achieved by picking the unique arc through
(x0 , f (x0 )), with x0 = 2−j · (k + 12 ), and the same first and second derivative at
x0 .
Once we have this upper estimate, we have again an approximation rate of
O(N −α ), with 2 < α < 3.

16
1.5 2-dimensional Potts-Functional
and its minimization
For the estimates for the different schemes to be useful, we need some means
of computing the minimizers efficiently. This is made possible by the so-called
Potts-Functional. We introduce the 2-D Potts-Functional on segmentations for the
discrete 2-dimensional image domain

S = {1, .., N1 } × {1, ..., N2 } for N1 , N2 ∈ Z

.
Given the image data y = (ys )s∈S , with (ys ) ∈ R, and the regularization
parameter γ ≥ 0, the Potts functional is defined

Hγ,y (P, yP ) = γ|P | + ky − yP k22 . (1.1)

Here yP is a constant function on all geometrical shapes p ∈ P , and k.k2 denotes


the l2 − norm X
kgk22 = |g(x)|2 .
x∈I

Since we use the l2 -norm, the optimal yP associated to a fixed partition P is ob-
tained by assigning each p ∈ P the mean value of y over p. Hence it is enough
to find the optimal P and compute yP from it. We write Hγ,y (P ) = Hγ,y (P, yP ),
where yP is understood to be the optimal piecewise constant function associated
to P .
A minimizer of Hγ,y will be denoted by Pγ , and the associated piecewise
constant image by yγ . The minimization of the Potts functional means to find
a γ-weighted balance between the number of the partitions P and the quality of
approximation error. The regularization parameter γ can be considered as a scale
parameter with the range [0, ∞). For γ = 0 the minimizer is in general the finest
possible segmentation and for γ → ∞ the segmentation consists of a single re-
gion.
Observe that the minimizer in equation (1.1) can be viewed as an optimal
approximation of y: Let ε = ky − yγ k2 then among all geometrical partitions
incurring an approximation error of at most ε, Pγ has the smallest number of ele-
ments. Therefore, by minimizing (1.1), we actually compute optimal approxima-
tion rates. In addition, the next remark shows that there exists a fast minimization
algorithm for (1.1). Combining these two observations, we see that the approxi-
mation rates derived above for the different schemes, are achievable by an efficient
algorithm.

17
Minimization algorithm

1. Local minimization, in other words, optimal geometrical form splits.


For each dyadic square, determine the geometrical split, i.e wedge split or
arc split q = w1 ∪ w2 which yields to the minimal local approximation
errorky|q − yq k22 . Here y|p is the restriction of y to p, and yp is the piecewise
constant function on q having the same mean values on wi as y. Then we
store the optimal split , the needed number of pieces and associated approx-
imation error.
For the quadtree case, it is just required to compute the mean value and local
approximation error.

2. Global minimization
Given γ, compute the optimal geometrical decomposition P from the data
stored in the first step. The quad-tree structure allows to do this by a simple
recursive algorithm, based on the following observation: Given an image y
and every parameter γ, we need to compare two candidates for the optimal
geometrical partition:
(a) Pγ is obtained by a single geometrical split of the dyadic square S; or
(b) Let S = S1 ∪ S2 ∪ S3 ∪ S4 denote the decomposition of S obtained
from a quad-split applied to S. Let Pγi denote the optimal geometrical
S of Si , associated
partition
i
the restriction y|Si and the parameter γ. Then
Pγ = i=1,..,4 Pγ

We observe that the second step only uses the approximation errors provided
by the first step, and it does not need to know the precise geometric nature of the
possible splits used in step one. Therefore we only need to adapt the first step to
the arclet setting.

18
Chapter 2

Digitization of the Arclet Scheme

In the previous chapter we introduced some geometrical structures (quad tree,


wedgelets, arclets) in the context of image approximation. Theoretical approxi-
mation rates have been discussed for the class of horizon functions. The choice
of arclets was motivated by these approximation rates, which are improved if the
edges are more regular. Therefore our idea consists in applying arclets represen-
tation to image approximation.
In practice however, we do not work anymore with images viewed as map-
pings from a continuous domain (e.g. [0, 1]×[0, 1]) into R, but with digital images
defined on pixel domains. Thus we need to build a good discretization scheme for
arclets which will make use of the ideas developed in [3]. This chapter discusses
the design and implementation of our discrete arclet scheme for digitals images
and points out some difficulties specific to the arclets case. This is the main origi-
nal contribution of this thesis.
As we pointed out in Section 1.5, the global minimization step of the arclet
scheme is the same as for wedgelets. Similarly, for the problem of ”painting” an
approximation of the image from a given arclet tree, one needs a procedure to
paint arc splits. Piecing together the different arc split to a whole image is easily
done recursively.
We will therefore describe only the ”local” problems that need to be solved.
They are the following:

• Best arc split: Given image data y, a center point c and a dyadic square q,
determine the best arc split q = w1 ∪ w2 obtained by splitting q along an arc
with center c. The best arc split is the one for which the error obtained by
approximating y on q by a function that is constant on w1 and w2 is minimal.
Given the best arc split, we also need to compute the associated approxima-
tion error.

19
• Painting an arc split: Given an arc split q = w1 ∪ w2 and greyvalues v1 , v2 ,
”paint” the function that takes vi on wi .
The first problem is the critical one from the point of view of computation
times: We must compute sums over image greyvalues for a large set of subsets of
the image domain. This gives big computation times, if it is not done properly.
Our solution to this problem depends on the so-called summation trick already
employed for wedgelets. It is a technique that allows to quickly compute sums
over various subsets of the image domain.

2.1 Why consider the summation trick?


In order to find the optimal approximation using the minimization of Potts func-
tional eq.(1.1), we need to compute the Euclidean norm of the error. Suppose
image data y are given for a dyadic square q and we have an arc split q = w1 ∪ w2 .
The best approximation y 0 which is constant on w1 and w2 is computed as
X 1
a = y 0 (x)x∈w1 = (y(x)) · (2.1)
x∈w
|w1 |
1

X 1
b = y 0 (x)x∈w2 = (y(x)) · (2.2)
x∈w2
|w2 |

After having constants a, b, we can directly compute the approximation error as


X X X X
(y(x) − y 0 (x))2 = y(x)2 − 2 y(x)y 0 (x) + y 0 (x)2
x∈q x∈q x∈q x∈q
X X X
= y(x)2 − 2 y(x)a − 2 y(x)b
x∈q x∈w1 x∈w2
X X
2 2
+ a + b
x∈w1 x∈w2
X X X
2
= y(x) − 2a y(x) − 2b y(x)
x∈q x∈w1 x∈w2

+ |w1 | a2 + |w2 | b 2
(2.3)

P P
where |w1 | = x∈w1 1 and |w2 | = x∈w2 1. Hence we can compute the approx-
imation error from suitable sums over q and w1 ,w2 . The summation trick now
provides a way to do this in O(1) operations, using lookuptables which are com-
puted beforehand in linear time. This way, the computation of the approximation
error is independent of the size of the dyadic square.

20
2.2 Summation over Continuous Domains
To make things simple, we first describe the summation trick for the continuous
setting. Let us fix a circle C with given radius r and center (xc , yc ) and an inte-
grable function defined on R2 .
Suppose that z = (x, y) is a point on the circle C. Then z is either on the
lower or on the upper arc. Let yu , yl : [xc − r, xc + r] → R be the parametrizations
of the upper and lower arcs as functions of the x-coordinate. We then define the
auxiliary upper and lower functions by
Z x Z
Ku (z) = f (s, t)dtds (2.4)
x0 −r 0≤t≤yu (x)
Z x Z
Kl (z) = f (s, t)dtds (2.5)
x0 −r 0≤t≤yl (x)

By definition, Ku (z) equals the integral over the values of y, integrated over
the domain between the x-axis and the upper arc up to z. Similarly, Kl corre-
sponds to the integral over the lower arc. Finally, let K(z) denote the integral
over the rectangle with lower left corner given by (0, 0) and upper right corner x0 .
Hence, in the case shown in figure 2.2. If z lies on the upper arc, we have
Z
f (x, y)dxdy = Ku (b) − Ku (a) + K(c) − K(d)
A

a b

c d
xc,yc

x0 x1

Figure 2.1: Example: Summation trick over continuous domain


which is computed in constant time from the values of Kl , Ku and K. The
discrete implementation of this scheme is the main contribution of this thesis.

21
2.3 Summation over discrete domains
Let us now treat the discrete case. In this section we are interested in discrete
domains which can be written as S = {1, ..., 2n } × {1, ..., 2n }. A dyadic square
in S is a subset {2j k + 1, . . . , 2j (k + 1)} × {2j m + 1, . . . , 2j (m + 1)} ⊂ S,
with 0 ≤ j ≤ n and 0 ≤ m, k ≤ 2n−j − 1. Our aim is the discretization of
the summation trick, and its application to arc splits of dyadic squares. The first
problem that arises is the definition is the proper definition of digital circles and
arcs.

Definition The digital circle with radius r ∈ N and center (xc , yc ) ∈ Z 2 , is


denoted by Cr (xc , yc ) and defined as the following set of pixels

Cr (xc , yc ) := {(x, y) ∈ Z 2 : r2 ≤ (x − xc )2 + (y − yc )2 < (r + 1)2 }

A digital arc is a subset of a digital circle that is connected with respect to


8-neighborhoods.

We remark that for a given center (xc , yc ),


[
Cr1 (xc , yc ) ∩ Cr2 (xc , yc ) = φ, if r1 6= r2 and Cr (xc , yc ) = Z 2 ,
r∈N

hence (Cr (xc , yc ))r∈N is a partition of Z 2 .


Hence we have described the boundaries of the summation domains. For the
practical implementation of summation trick we need to solve the following prob-
lems:

• To run through a digital arc, given starting and ending point on a digital
circle. An effective solution for this is needed for the computation of the
lookuptables containing cumulative sums, but also for painting arclet ap-
proximations.

• Given a center point and a dyadic square q, finding maximum and minimum
radius of circles that intersect q.

• Determining the intersection points between arc and dyadic square. This is
needed in particular to determine which entries of the lookuptables must be
used for the computation of local approximation errors.

22
2.3.1 Algorithm to Traverse a Circle
Here we address the problem of drawing a digital circle on the integer x-y grid.
The algorithm has to traverse along a digital circle, between any two points lying
on the circle. Given a pixel on the circle, the next pixel (xnext , ynext ) is found by
solving the minimum residual problem [11], i.e., by finding the next lattice point
that minimizes | (x − x2c ) + (y − yc )2 − r2 |. There will be only two choices
close to the lattice point (x, y) that we have to investigate : 1) lattice point on x
axis which is close to point (x, y) and 2) a lattice point on y axis, upper or below
point (x, y). Since the drawing of a complete circle can be done by the symmetry
property of the circle let us first consider drawing a circle in the first octant, in the
counterclockwise direction. For convenience, we define a notation for the resid-
uals x2 + y 2 − r2 . To the right or left of point (x, y) can be denoted εx , a lattice
point is above or under a point (x, y) can be denoted εy

ε =x2 + y 2 − r2 ,
εx =(x − 1)2 + y 2 − r2 = ε − 2x + 1
εy =x2 + (y + 1)2 − r2 = ε + 2y + 1
εxy =(x − 1)2 + (y + 1)2 − r2 = ε − 2x + 2y + 2

From any given point on the arcs, (x, y) , our arc drawing algorithm should be able
to give the best next point on the digital circle. The next point will be referred to
the one that leads to a minimum residual. Note that drawing an arc in counter-
clockwise in the first octant, the possible choices to go for the next lattice would
possibly be north(N), which change the residual from ε to εy or northwest(NW),
which changes from ε to εxy

First Octant arc

x,y ← r,0
while y < x do
plot(x,y)
if −εxy < εy then
x←x−1
else y ← y + 1

23
A B C D
єy
є x,y

єx є

Figure 2.2: Nomenclature for residuals for various steps in the first octant with
representative arcs. The point marked ² is the current point. Residuals with respect
to a given circle are negative at points inside,positive at points outside.

From figure 2.2, if εxy ≥ 0 (the northwest neighbor lies outside the arc as
with arc A), then εy > 0. Thus −εxy ≤ 0 < εy , so the NW step will be taken.
Similarly, if εxy < 0 and εy ≤ 0 (arc D), then −εxy > 0 ≥ εy . The N step will be
taken. Finally, if εxy < 0 and εy > 0 (arc B and C), then −εxy < εy .

The second octant differs from the first octant only in the step, in this case we
consider the west(W) and northwest(NW) lattice point. If we calculate ε incre-
mentally and substitute from (2.2) the notation can be generalized the definition
for the residuals
ε = x2 + y 2 − r 2 ,
εx =(x + ∆x)2 + y 2 − r2 = ε + 2x∆x + 1
εy =x2 + (y + ∆y)2 − r2 = ε + 2y∆y + 1
εxy =(x + ∆x)2 + (y + ∆y)2 − r2 = ε − 2x∆x + 2y∆x + 2

where the step ∆x, ∆y have values±1, chosen appropriately for each quadrant.
The pseudo in first and second quadrant is both equivalent with the sign of every
residual changed.

1.Quadrant 2.Quadrant
if −εxy < εy then if −εxy < εx then
x ← x + ∆x y ← y + ∆y
if εxy < −εx then if εxy < −εy then
y ← y + ∆y x ← x + ∆x

24
Changing the sign of ε , we must adjust all the differences and both ε which
are involved in computing. The detail to draw an approximate arc from (x, y) to
(x1 , y1 ) in the integer case with integer radius r appear in this algorithm

25
Procedure arc(x, y, x1 , y1 , rsq, dir) ∈ Z
begin
procedure Negate ;
begin
ε, ∆x ε, ∆y ε, ∆2 ε ← −ε, −∆x ε, −∆y ε, −∆2 ε;
end
procedure sgn2(a, b ∈ Z) : ;
begin
procedure sgn(a ∈ Z);
begin
if a < 0 then RETURN −1 else if x = 0 then
RETURN 0
else
RETURN 1
end
end
if a 6= 0 then
RETURN sgn(a)
else
RETURN sgn(b)
end
end
initialize ∆x, ∆y, ε, ∆x ε, ∆y ε, ∆2 ε
repeat
plot(x, y);
εx , εy , εxy ← ε + ∆x ε, ε + ∆y ε, ε + ∆x ε + ∆y ε;
if −εxy < εy then
x, ε, ∆x ε ← x + ∆x, ε + ∆x ε, ∆x ε + ∆2 ε;
end
if εxy < −εx then
y, ε, ∆y ε ← y + ∆y, ε + ∆y ε, ∆y ε + ∆2 ε;
end
if x = 0 then
∆y, ∆y ε ← −∆y, −∆y ε + ∆2 ε ;
Negate ;
end
if y = 0 then
∆x, ∆x ε ← −∆x, −∆x ε + ∆2 ε ;
Negate ;
end
until x = x1 and y = y1;
end

26
Notice: When (x1, y1) = (x, y), the algorithm will plot a complete approxi-
mate circle .

2.3.2 Cumulative sum computation


Given a center point (xc , yc ) ∈ Z 2 , each point (x, y) ∈ Z 2 lies on precisely one
circle around (xc , yc ). We want to compute a lookuptable containing for each
point (x, y) the sum over all pixels below the arc through (x, y), starting at the
leftmost pixel. We differentiate between lower arcs and higher arcs.
The lookuptable is computed by first summing cumulatively in the vertical
direction, and then along each arc. The computation of vertical cumulative sums
is described in the next procedure:
Procedure MakeColSum( data:z ∈ Z,N1 , N2 ∈ N, Result:OBJECT)
input : an array of data size N1 × N2
output : array I holding vertical sum value. I and dimensions are stored in an
OBJECT: Result
begin
New(I,N1 , N2 );
for x ← 0 to N1 − 1 do
I(x,0) ← 0
end
for y ← 1 to N2 − 1 do
I0,y ← 0 for x ← 1 to N1 − 1 do
Ix,y ← z(x,y) + I(x,y−1)
end
end
stored data Result.I ← I; Result.N1 ← N1 ; Result.N2 ← N2
end

Many cases can occur when an arc intersects with a rectangle but at most the
number of intersection points are 8 points. A difficulty in computing the cumu-
lative sums along an arc-shaped is noticed when a pixel curve line intersects the
rectangle with its right or left arc of the circle. Hence, the summation along the arc
will be considered the computation trick into upper and lower half of the circle.
Given any circles with center point(xc , yc ) This reference line (y = yc ) seperates
the circle into upper and lower part. Both 2 points on the leftmost and rightmost
point of circle must belong to either upper part or lower part. We consider both
points into the set points of upper half circle.

27
Procedure CircleSums(: OBJECT)
store the summation of the vertical summation along curve by traversing pixel:
start at (x, y) in which information of the previous pixel on arc be stored
(prevx, prevy ), and sum up by using 2 sources colsum(MakeColSum:Object) and
original image array
local : circlesum : 2D − array ; prevx, prevy ∈ Z; val ∈ R; cx , cy ∈ Z
begin
procedure DotUpper:(x, y ∈ Z);
begin
if x > prevx then
val ← val + colsum[x, y]
else if y > prevy then
val ← original[x, y]
end
circlesum[x, y + 1] ← val;
prevx ← x ; prevy ← y;
end
procedure DotLower:(x, y ∈ Z);
begin
if x > prevx then
val ← val + original[x, y] + colsum[x, upper] − colsum[x, y]
(*sum up columns above point*)
else if y < prevy then
val ← original[x, y]
end
circlesum[y + 1, x] ← val;
prevx ← x ; prevy ← y;
end
end

28
r
a b

Figure 2.3: Illustration of summation trick

We compute the area sum following cumulative vertical array in the upper half
circle to clockwise direction ,on the other hand, compute the area sum following
the vertical sum to counterclockwise for lower half circle. Since the summation
of pixels on a vertical line is implicitly cut off into the consideration of upper
and lower half circle. Summation trick within an arc-shaped in this case must
be treated carefully otherwise it would return an incorrect sum value. Consider
figure ??

Figure 2.4: Show the direction of computation sum of upper half and lower half

Imagine the two pixels on the circumference which are on the same level of
a horizon diameter of Cr (xc , yc ). It is always problematic when such pixels are
in the set of the curve line between of an arc and a rectangle. Once we take
calculation on that point as it in the upper half circle, we would not reuse that

29
Figure 2.5: an example when the problem is at the right or left circle cut the edge.

point again for summation area within the lower part of circle. As our strategy, we
separate and store the data in upper and lower part of circle by shifting a position
in the circle line up one pixel and store information of circle when we work on the
upper part.

2.3.3 Find minimum and maximum radius.


In this section we consider the following problem: Given a center point (xc , yc )
and a dyadic square q, determine the radii of circles around (xc , yc ) that could
intersect q. The following procedure solves this problem.

30
Procedure FindIntersectingCircle( xc , yc , x, y, w, h ∈ N ; VAR
rmin , rmax ∈ N )
passes minimum and maximum offset rmin ,rmax of circles Cri (xc , yc ) that
intersect rectangle where the left bottom corner is (x, y) and its size (w × h).
local : dist, distmin , distmax ∈ Z
begin lp m
dist ← (xc − x)2 + (yc − y)2 (* left bottom *)
distmax ← dist distmin ← dist
lp m
dist ← (xc − x − w + 1)2 + (yc − y)2 (* right bottom *)
if dist > distmax then distmax ← dist end ;
if dist <
lpdistmax then distmin ← dist end ; m
dist ← (xc − w + 1)2 + (yc − y − h + 1)2 (* left top *)
if dist > distmax then distmax ← dist end ;
if dist <
lpdistmax then distmin ← dist end ; m
dist ← (xc − x − w + 1)2 + (yc − y − h + 1)2 (* right top *)
if dist > distmax then distmax ← dist end ;
if dist < distmax then distmin ← dist end ;
rmax ← distmax ;
if (xc ≥ x) and (xc ≤ x + w) and (yc ≥ y) and (yc ≤ y + h − 1) then
rmin ← 1;
else if (xc ≥ x) and (xc < x + w) then
if yc ≤ y then
rmin ← y − yc
else if (yc ≥ y + h) then
rmin ← yc − y − h + 1
end
else if (yc ≥ y) and(yc < y + h) then
if xc ≤ x then
rmin ← xc − x
else if xc ≥ x + w then
rmin ← xc − x − w + 1
end
else
rmin ← distmin
end
end
end

31
2.3.4 Intersection of arcs with rectangle
In this section, we determine the intersection points of the boundary of a rectan-
gle with a digital circle, if they have any, by using a geometrical approach on x-y
grid. The rectangle is composed of two horizontal lines and two vertical lines.
Therefore the circle-rectangle intersection problem can be decomposed into four
subproblem by finding the intersection points of these lines. The idea is to deter-
mine the distance between the center of the circle and each line.
Consider a single line. Then, if the distance of this line and the center of the
circle is less than the radius, then there will be no intersection, otherwise, there
are at most two intersection points. The location of intersections can be found by
Pythagoras’ Theorem. In other word, let (xc , yc ) be the center point of a circle
Cr ; r be radius and a rectangle R with the size of (w × h) is located a right corner
at position (rx, ry)

We need to consider the following terms:


• the right edge : (rx − xc )2 ≤ r2
• the left edge: ((rx + w − 1) − xc )2 ≤ r2
• the lower edge : (ry − xc )2 ≤ r2
• the upper edge: ((ry + h − 1) − xc )2 ≤ r2

Procedure LineCircleIntersectV(rx , cx , cy , cr ∈ Z; VAR


x1 , y1 , x2 , y2 ∈ Z): BOOLEAN)
Returns TRUE if circle defined by Ccr (cx , cy ) and offset l intersects rectangle
rx , ry , w, h, otherwise FALSE. Intersections are passed in (x1 , y1 ) and (x2 , y2 ).
local : rsq, dsq ∈ Z; dy ∈ R
begin
dsq ← (rx − cx )2 ;
rsq ← (cr )2 ;
if rsq > dsq
√ then
dy ← rsq − dsq;
x1 ← rx ; x2 ← rx ; y1 ← cy − dy ; y2 ← cy + dy;
return TRUE
else
return FALSE
end
end

The intersection points we obtain from previous paragraph may or may not be
intersecting the circle because so far we considered infinite horizontal and vertical

32
lines. Before further progress, we need to determine those intersection points that
are in the range of rectangle boundary. But this is decided by a simple comparison
of coordinates with the corners of the rectangle.

The next problem consists in deciding if the intersection points contain a cor-
ner point of the rectangle. Under some conditions we will not allow the corner
as an intersection point. We have to consider if the particular corner point is ac-
ceptable. A corner point is acceptable if one of its neighbours on the arc is in the
inside of the rectangle. There are 4 cases that can tell us to admit the point by
consideration of the center point (xc , yc ) position within these regions.

(xc,yc)

(xc,yc)

(a) (b)

Figure 2.6: From case (1) show 2 possible examples (cutting edge by arc ), (b)
we accept a corner point as the intersection, (a) this corner point will not be taken
into account.

1. If the point(x, y) is a bottom left corner, we will accept the point only if the
center point is not in these conditions
a1. (xc > x) and (yc > y) : Region 2 without boundary.
b1. (xc ≤ x) and (yc ≤ y) : Region 4 including boundary.
2. If the point is a bottom right corner, we will accept the point only if the
center point is not in these conditions
a2. (xc < x) and (yc > y) : Region 1 without boundary.
b2. (xc ≥ x) and (yc ≤ y) : Region 3 including boundary.
3. If the point is a upper left corner, we will accept the point only if the center
point is not in these conditions

33
1 2 1 2

4 3 4 3

1 2
1 2

4 3
4 3

Figure 2.7: a rectangle and show the 4 regions (1,2,3,4 for all respective corners.)

a3. (xc > x) and (yc < y) : Region 3 without boundary.


b3. (xc ≤ x) and (yc ≥ y) : Region 1 including boundary.

4. If the point is a upper right corner, we will accept the point only if the center
point is not in these conditions

a4. (xc < x) and (yc < y) : Region 4 without boundary.


b4. (xc ≥ x) and (yc ≥ y) : Region 2 including boundary.

34
Procedure RectCircleIntersect(rx , ry , rw , rh , cx , cy , cr ∈ Z;
VARq : pointQueue : RECORD)
Intersections are passed in (x1 , y1 ) and (x2 , y2 ). Then store the set of intersection
points in p:pointQueue:RECORD
local : x1 , y1 , x2 , y2 ∈ R
begin
P ointQueue 6= N IL
--- Left Edge ---
if (rx , cx , cy , cr , x1 , y1 , x2 , y2 ) then
if (ry ≤ y1 ≤ ry + rh − 1) and CheckCorner(x1 , y1 ) then
CompareAndInsert(q, cx , cy , x1 , y1 )
if (ry ≤ y2 ≤ ry + rh − 1) and CheckCorner(x2 , y2 ) then
CompareAndInsert(q, cx , cy , x2 , y2 )
--- Right Edge ---
if (rx + rw − 1, cx , cy , cr , x1 , y1 , x2 , y2 ) then
if (ry ≤ y1 ≤ ry + rh − 1) and CheckCorner(x1 , y1 ) then
CompareAndInsert(q, cx , cy , x1 , y1 )
if (ry ≤ y2 ≤ ry + rh − 1) and CheckCorner(x2 , y2 ) then
CompareAndInsert(q, cx , cy , x2 , y2 )
---Bottom Edge ---
if (ry , cx , cy , cr , x1 , y1 , x2 , y2 ) then
if (rx ≤ x1 ≤ rx + rw − 1) and CheckCorner(x1 , y1 ) then
CompareAndInsert(q, cx , cy , x1 , y1 )
if (rx ≤ x2 ≤ rx + rw − 1) and CheckCorner(x2 , y2 ) then
CompareAndInsert(q, cx , cy , x2 , y2 )
---Top Edge ---
if (ry + rh − 1, cx , cy , cr , x1 , y1 , x2 , y2 ) then
if (rx ≤ x1 ≤ rx + rw − 1) and CheckCorner(x1 , y1 ) then
CompareAndInsert(q, cx , cy , x1 , y1 )
if (rx ≤ x2 ≤ rx + rw − 1) and CheckCorner(x2 , y2 ) then
CompareAndInsert(q, cx , cy , x2 , y2 )

(*9 o’clock point of circles is within rectangle,


necessary with distinction of upper and lower
rectangle*)
if (rx < (cx − cr ) < (rx + rw )) and (ry < cy < (ry + rh )) then p ← q if
p 6= N IL then p.next ← N IL q.P ut(p) (*put first element to
last position*)
end
35
By following those conditions, we can determine all acceptable intersection
points and obtain a set of the intersection points which have 2-4 points either on
the upper circumference or lower circumference. We have to reorder these points
with respect to the address in upper half or lower half position in order to properly
do the summation over the area, using the previously computed lookuptables. This
will be done in the next subsection.

2.3.5 Ordering of the Intersection Points


After computing all intersection points, we need to reorder them to ensure that the
intersections point from left to right for upper half circle. Applying the summation
trick on the lower half circle case, we flip the ordering set again in order to get the
set of points from right to left position, and thus applied the summation trick of
the lower case.
Procedure(CompareAndInsert) is called to compare and check the intersection
points and move each point into the ordering. The idea is to check the ”tangent”
function between two candidates (x1 , y1 ) and (x2 , y2 ). The tangent function is
defined by tan(x) = sin(x)
cos(x)
. We consider each point position as if it is the time on
a clock.
The detail of the implementation is shown in the procedure (CompareAndInsert)

Figure 2.8: the tangent function : −π


2
≤x≤ −3π
2

36
Procedure CompareAndInsert(q : RECORD; cx, cy ∈ Z;x, y ∈ R)
Get the points and call the Procedure(IsBeforeOnCircle) ⇐ BOOLEAN value will
be returned whether which point is the former and the latter.
begin
p ← q.head while p is not empty and
IsBeforeOnCircle(x1, y1, x2, y2) do get the next point
if (p is not empty)AND (p.xr = x)AND(p.yr = y) then return
new, p;
end

Procedure IsBeforeOnCircle(x1 , y1 , x2 , y2 ∈ R):BOOLEAN


compares between the two points then it returns TRUE if (x1 , y2 ) is in right order
of (x2 , y2 ), otherwise returns FALSE
begin
(* exclude the same time *)
if x1 = x2 and y1 = y2 then return FALSE end ;
if y1 = 0 then
if x1 < 0 then return TRUE (*9 o’clock or 3 o’clock?*)
if x1 < 0 then return TRUE (*9 o’clock,before any other
points*)
else if y2 < 0 then return TRUE (*(x2 , y2 ) is on lower
half*)
else return FALSE end ;

--- (x1 , y1 ) is on upper half---


else if y1 > 0 then
if y2 < 0 then return TRUE (*(x2 , y2 ) is on lower half*)
else if (x1 ∗ y2 < 0) < (x2 ∗ y1 ) then return TRUE (*same half
check*)
else return FALSE end ;

--- (x2 , y2 ) is on lower half---


else
if y2 ≥ 0 then return FLASE (*(x2 , y2 ) is on upper half*)
else if (x1 ∗ y2 < 0) < (x2 ∗ y1 ) then return TRUE (*same half
check*)
else return FALSE end ;
end
end

37
We have all the intersections of each dyadic then we can draw the rectangle
and the arc with corresponding to the intersection points

2.3.6 Determining the best arc split


In the approximation step, we need to find the best arc in each dyadic square, i.e.
the arc yielding smallest approximation error.
Given an arc through the dyadic square, all intersection points have been rear-
ranged in ordering as discussed in Section(2.3.5).
The next step is to find the summation area under each arc segment in the
dyadic square. In order to apply the summation trick, we will first have to de-
compose the arc into several pieces.In each piece of geometrical arc-shaped in
dyadic square, we need the summation values and the number of pixels which are
in that particle. Any digital arcs in dyadic square will be determined by Proce-
dure(Split). Since we use summation strategies by lower and upper half of circle,
Procedure(Split) will split that arc part into pieces using diameter of circle as a
based line. Thus we compute summation area and count the number of pixels
seperately in each pieces. They will be pieced back together in the last step for
overall sum values and number of pixels of each dyadic square.

Procedure Split(ry , rh , cy ∈ Z; VAR ylow , hlow , yup , hup ∈ Z;VAR


lower,upper:BOOLEAN);
splits the area in upper and lower part based on diameter :cy of circle
Cr (cx , cy )and in the rectangle(rx , ry , w, h) and it will check if there are lower or
upper parts by return TRUE or FALSE.
begin
if ry ≤ cy then ylow ← ry ;
hlow ← Min(cy − ry + 1, rh ) else hlow ← 0 end ;
if (ry + rh ) > cy then yup ← Max(ry , cy );
hup ← Min(ry + rh − cy , rh ) else hup ← 0 end ;
if hup > 1 then upper← TRUE else upper ← FALSE;
if hlow > 1 then lower← TRUE else lower ← FALSE;
end

38
For each case of geometrical shape piece uses individual pseudo code e.g Pro-
cedure(RectContent), Procedure(UpperQContent), Procedure(LowerQContent) for
calculating the summation and number of pixels.

Procedure RectContent(x1 , y1 , x2 , y2 ∈ Z; rec ∈ Rw×h ) ∈ R


Returns sums of values within the rectangle defined by lower left and upper right
points (x1 , y1 ) and (x2 , y2 ), provided that rec is corresponding rectangle sum array.
begin
if (x1 > x2 ) or (y1 > y2 ) then return 0; end ;
s ← recx2 ,y2 ;
if x1 > 0 then s ← s − recx1 ,y2 end ;
if y1 > 0 then s ← s − recx2 ,y1 end ;
if x1 > 0 and y1 > 0 then s ← s + recx1 ,y1 end ;
return s;
end

Procedure UpperArcContent(plef t , pright : P oint : Record ∈ Z2 ;


lowy ∈ Z; omitLowestLine : BOOLEAN )
Returns sums of values within the arc content in upper part of circle in rectangle
defined by left and right points ,(pl.x, pl.y ) and(pr.x, pr.y )
local : lef tx , lef ty , rightx , righty ∈ Z ;sum ∈ R
begin
lef tx ← pl.x ; lef ty ← pl.y ; rightx ← pr.x ; righty ← pr.y ;
if omitLowestLine then DEC (lowy) end ;
sum ← [righty + 1, rightx ];
if lowy ≥ 0 then sum ← sum − rectsum[lowy, rightx ]end ;
sum ← sum − circlesum[lef ty + 1, lef tx ] + colsum[lef ty , lef tx ];
if (lowy ≥ 0) and (lef tx > 0) then
sum ← sum + rectsum[lowy, lef tx − 1]end ;
return sum;
end

Above pseudo code collects and passes all information that we need for the
approximation step. We use the summation trick to calculate the squared error in
each pieces in dyadic square. The minimum sum square error is the key value to
get the best arc.

39
Procedure LowerArcContent(plef t , pright : P oint : Record ∈ Z2 ;
upy ∈ Z)
Returns sums of values within the arc content in lower part of circle in rectangle
defined by left and right points ,(pl.x, pl.y ) and(pr.x, pr.y
local : lef tx , lef ty , rightx , righty , lowy ∈ Z ;sum ∈ R
begin
lef tx ← pl.x ; lef ty ← pl.y ; rightx ← pr.y;
lowy ← (lef ty , righty ) − 1 ;
sum ← circlesum[righty , rightx ] − circlesum[lef ty, lef tx] +
colsum[upper, lef tx ] − colsum[lef ty , lef tx ] + original[lef ty , lef tx ];
return sum − (lef tx , upy + 1, rightx , upper)
end

2.4 Painting an arc split


Suppose we have a dyadic square q, a center point (xc , yc ) and radius r, such that
the corresponding arc yields an arc split q = w1 ∪ w2 . We need a procedure
that assigns each pixel in wi a fixed value vi . This can be done combining the
algorithms from above: Procedure (FindIntersectingCircle) gives all possible radii
of arcs intersecting q. For each such radius, the corresponding arc a through q is
completely in w1 or w2 . This can be decided by comparing the radius of a with
the radius of the arc giving the split q = w1 ∪ w2 . The intersection points of a with
the boundary of q are found with Procedure RectCircleIntersect. The arc between
these intersection points is obtained by Procedure arc.

40
Procedure UpperQContent(q : P ointQueue; rx , ry , rw , rh ∈ Z;
omitLowestLine : BOOLEAN )
Returns sums of values within the rectangle (rx , ry , rw , rh ) for upper content
local : p1 , p2 ∈ P oint : RECORD[x, y, nextx, nexty];
ml , mr ∈ Z;sum ∈ R
begin
ml ← rx ; mr ← rx + rw − 1; p1 ← q.head;
if p1 is NIL then return ;
p2 ← p1 .next
if (p2 .y = ry + rh − 1) and (p2 .x 6= rx + rw − 1) then
ml ← p2 .next;
sum ← UpperArcContent(p1 , p2 , ry , omitLowestLine);
p1 ← p2 .next (*further intersection*)
if p1 6= N IL then
p2 ← p1 .next; mr ← p1 .x − 1;
sum ← sum + UpperArcContent(p1 , p2 , ry , omitLowestLine)
end
if omitLowestLine then
sum ← sum + (ml, ry + 1, mr , ry + rh − 1)
else
sum ← sum + (ml , ry , mr , ry + rh − 1)
end
else if (p1 .yy + rh − 1) or (p1 .x = rx ) then
mr ← p1 .x − 1;
if omitLowestLine then
sum ← (ml , ry + 1, mr , ry + rh − 1);
else
sum ← (ml , ry , mr , ry + rh − 1)
end
sum ← sum + UpperArcContent(p1 , p2 , ry , omitLowestLine)
else
sum ← UpperArcContent(p1 , p2 , ry , omitLowestLine)
end
end return sum
end

41
Procedure LowerQContent(q : P ointQueue; rx , ry , rw , rh ∈ Z)
Returns sums of values within the rectangle (rx , ry , rw , rh ) for lower content
local : p1 , p2 ∈ P oint : RECORD[x, y, nextx, nexty]; ml , mr ∈ Z;
sum ∈ R
begin
ml ← rx ; mr ← rx + rw − 1; p1 ← q.head;
if p1 is NIL then return ;
p2 ← p1 .next
if (p2 .y = ry + rh − 1) and (p2 .x 6= rx + rw − 1) then
mr ← p2 .x − 1;
sum ← LowerArcContent(p2 , p1 , ry + rh − 1); p1 ← p2 .next
(*further intersection*)
if p1 6= N IL then
p2 ← p1 .next; ml ← p1 .x + 1;
sum ← sum + LowerArcContent(p2 , p1 , ry + rh − 1)
end
end ;
sum ← sum + (ml , ry , mr , ry + rh − 1) else if (p1 .y = ry + rh − 1) or
(p1 .x = rx +rw − 1)then
ml ← p1 .x + 1;
sum ←
LowerArcContent(p2 , p1 , ry + rh − 1 + (ml , ry , mr , ry + rh − 1)
else
sum ← LowerArcContent(p2 , p1 , ry + rh − 1)
end
end return sum
end

42
Procedure CircleRectValues(VAR rx , ry , rw , rh , cx , cy ∈ Z; VAR
Sm, s ∈ R; VAR p ∈ Z);
Passes mean sum and sum of squares s,p in arc partition on dyadic rx , ry , rw , rh .
global : Summation matrices RY (data), RS (squared data) and RP
(points)
local : yu p, hu p, ylow , hlow ∈ Z ; q : P ointQueue : RECORD ∈ Z;
low, up :BOOLEAN
begin
Split(ry , rh , cy , ylow , hlow , yu p, hu p);
if low then
RectCircleIntersect(rx , ylow , rw , hlow , cx , cy , i, q);
ReoderForLower(cx , cy , i, q);
Sm ← Sm + LowerQContent(q, rx , ylow , rw , hlow , RY );
s ← s + LowerQContent(q, rx , ylow , rw , hlow , RS );
p ← p + LowerQContent(q, rx , ylow , rw , hlow , RP );
else if RectInCircle(rx , ylow , rw , hlow , cx , cy , i) then
Sm ← Sm+RectContent(rx , ylow , rx +rw −1, ylow +hlow −1, RY );
s ← s + RectContent(rx , ylow , rx + rw − 1, ylow + hlow − 1, RS );
p ← p + RectContent(rx , ylow , rx + rw − 1, ylow + hlow − 1), RP ;
end

if up then
RectCircleIntersect(rx , yup , rw , hup , cx , cy , i, q);
Sm ← Sm + U pperQContent(q, rx , yup , rw , hup , low, RY );
s ← s + U pperQContent(q, rx , yup , rw , hup , low, RS );
p ← p + U pperQContent(q, rx , yup , rw , hup , low, RP );
else if RectInCircle(rx , yup , rw , hup , cx , cy , i) then
if low then
Sm ← Sm+RectContent(rx , yup +1, rx +rw −1, yup +hup −1, RY );
s ← s + RectContent(rx , yup + 1, rx + rw − 1, yup + hup − 1, RS );
p ← p + RectContent(rx , yup + 1, rx + rw − 1, yup + hup − 1, RP );
else
Sm ←
Sm + RectContent(rx , yup + 1, rx + rw − 1, yup + hup − 1, RY );
s ← s+RectContent(rx , yup +1, rx +rw −1, yup +hup −1), RS ;
p ← p+RectContent(rx , yup +1, rx +rw −1, yup +hup −1, RP );
end
end

end

43
Procedure FindBestRadius(rx , ry , rw , rh ∈ Z; VAR r ∈ Z; VAR
µ1 , µ2 , ssq ∈ R)
Passes radius parameter r, means µ1 and µ2 of arcs with radius(r) in rectangle
rx , ry , rw , rh with minimal sum of squares ssq
global : Summation matrices C Y , RY , W Y (data), C S , RS , W S (squared
data) and C P , RP , W P (points)
local : m1 , m2 , m3 , s1 , s2 , s3 , p1 , p2 , p3 , s ∈ R; i, rmin , rmax ∈ Z
begin
min ← ∞
FindIntersectingCircle(cx , cy , rx , ry , rw , rh , rmin , rmax );
m3 ← RectContent(rx , ry , rx + rw − 1, ry + rh − 1, RY );
s3 ← RectContent(rx , ry , rx + rw − 1, ry + rh − 1, RS );
p3 ← RectContent(rx , ry , rx + rw − 1, ry + rh − 1, RP );
for i ← rmin to rmax do
CircleRectValues(rx , ry , rw , rh , rmin , rmax );
s2 ← s3 − s1 ; m2 ← m3 − m1 ; p2 ← p3 − p1 ;
if p1 > 0 then s1 ← s1 − m21 /p1 end ;
if p2 > 0 then s2 ← s2 − m22 /p2 end ;
if s1 + s2 < s then
s ← s1 + s2 ; r ← i; µ1 ← m1 /p1 ; µ2 ← m2 /p2 ;
end
end
end

44
Chapter 3

Examples and Experiments

In this Chapter we illustrate the methods and algortihms described in the previous
chapters with some simulation results. These results are performed with the code
which we have implemented in Oberon. This implementation relies on the algo-
rithm described in Section .

3.1 Oberon implementation


The algorithms for the computation of arc segmentations have been implemented
in Oberon. Oberon is the name of an operating system and a programming lan-
guage in the Pascal/Modula tradition. The operating system Oberon is a single
user, multi-tasking system that runs on the top of operating system like Windows
and Linux.
The software uses functionalities of the packages Voyager [13] and ANTSInF ields
[7]. Voyager is helpful for exploring the feasibility of portable and extensible sys-
tem for simulation and data analysis systems. The basic tools from ANTSInF ields
can be used for handling and visualization. The framework Oberon software is
portable between different operating systems.
There are free available versions of the software for Linux, Windows provided on
http://www.antsinfields.de and http://www.wedgelet.de
In figure (3.1), we display a frame with the classical interface for an Oberon
workspace. In one of the subwindows we see the panel implemented in this thesis,
which we display in figure 3.1 .

45
Figure 3.1: Arclet Segmentation with Oberon/Voyager/Ants on Windows

46
Panel

Figure 3.2: Software panel of geometrical segmentation, e.g. wedgelet, arclet


with Oberon/Voyager/Ants on Linux

This panel is a specific interface : an Oberon function corresponds to each


button . Its functionalities are the following:

1. File : use to load an image file in different formats, including *.pgm

2. Noise : white gaussian noise can be added to the image. The user can set
the variance of this noise.

3. New Tree : create a new tree for the size of the image. This tree contains a
(still) empty quadtree structure and will be used in each further step,

47
4. Rect Model : Plug-in rectangle model. This model contains the best constant
approximation in each rectangle of the quadtree.

5. Wedgelet : Plug-in wedge model in order to do wedge segmentation and find


the best wedge approximation. Input parameters are the range of angles and
step size (starting angle and ending angle with any step size). This model
contains the best constant approximation over a wedge split of a rectangle,
for each rectangle.

6. Arclet : Plug-in arc model in order to do arc segmentation and find the best
arc approximation. Input are the coordinate of center points of circles (a
start x,y cordinate and an end x,y with the step size control in both x and y
direction. This model contains the best constant approximation over an arc
split of a rectangle, for each rectangle.

7. Scroll bar ’Logγ’ : control a number of pieces and resolution of the image
or user can insert a value in the blank box then press enter to pass the pa-
rameter value. For each γ, the optimal solution is performed, by selecting
the leaves of the tree, according to the score comparison.

8. Show array/ tree/ both(array and tree) : graphic display of the reconstructed
image (and/or) according wedge/arc/quadtree.

In order to measure the quality of our approximation images we used the stan-
dard Peak to Signal Noise Ratio(PSNR), with the measured result in Decibel dB.
It is a logarithmic scaling of the normalized inverse of the mean square error. Let
us consider an original digital image y of size w × h, with quantized gray levels
in a range y ∈ [0, d − 1]. Typically we deal with grey value depth d = 256. We
want to measure the error between this image and any reconstructed image ŷ. In
this context, the PSNR is given by

d2
P SN R(y, ŷ) = 10 ∗ log10 ( )
M SE
where MSE denotes the Mean Square Error

ky − ŷk22 X 1
M SE = = |y(p) − ŷ(p)|2 ·
w∗h p∈Ω
w∗h

where Ω denotes the set of pixels and y(p) is the grey value at the pixel p.
Despite some disadvantages (PSNR does not exactly, it is sensible to noise),
the PSNR provides a straightforward and relatively robust measure for comparing
image reconstruction qualities. Furthermore it corresponds to an error measure

48
in the l2 setting, which seems convenient, since our functional minimization also
relies on l2 -error. Although it depends on the contents of the image (presence of
textures, noise, pure geometrical features), one can say that a high PSNR values
(typically higher than 35 dB) correspond to a very good reconstruction quality
for most natural images. In contrast, one can say that low PSNR values(typically
below 25 dB) correspond to very coarse representations, where only a few signif-
icant features are still recognisable. Increasing PSNR corresponds to increasing
quality.
On the following we present some comparison results of our approximation
schemes (wedgelets, arclets). In each plotted rate-distortion curve, we represented
the PSNR versus number of pieces required by the model. Thus the x-axis corre-
sponds the number of pieces and the the y-axis to the PSNR values.

Figure 3.3: Example the various psnr values on image ’bird’ (left) PSNR = 25 ,
(middle) PSNR=30, (right) PSNR=40

We evaluated our algorithm and the effect of different parameters. Several


circle parameters were tested . All experiments were performed over the original
images without noise.
For our simulations, we worked with some standard images ’barbara’,’peppers’,’camera’,
widely used in the literature. We also made experiments with a cartoon image
(’obelix’), with two other natural images (’bird’,’splash’) which we expect to have
high geometrical content, and with a pure artificial geometrical image ’circles’.

49
Image ’Bird’, 256 x 256. PSNR against number of segments.

27

26

25
PSNR

24 Dyadic+Wedgelet
Dyadic+Wedgelet+Arclet
23

22

21

20
0 50 100 150 200
Number of pieces

Figure 3.4: Plot for image ’bird’ : PSNR against number of segments for a wedge
model (red) and combination of wedge and arclet model(blue)

50
Image ’Circles’, 256 x 256. PSNR against number of segments.
140

120
Dyadic+Wedgelet
Dyadic+Wedgelet+Arclet
100

80
PSNR

60

40

20

0
0 100 200 300 400 500 600
Number of pieces

Figure 3.5: Plot for image ’circles’ : PSNR against number of segments for a
wedge model (red) and combination of wedge and arclet model(blue)

Image ’Peppers’, 256 x 256. PSNR against number of segments.


25

24.5 Dyadic+Wedgelet
Dyadic+Wedgelet+Arclet
24

23.5

23
PSNR

22.5

22

21.5

21

20.5

20
100 200 300 400 500 600 700 800
Number of pieces

Figure 3.6: Plot for image ’peppers’ : PSNR against number of segments for a
wedge model (red) and combination of wedge and arclet model(blue)

51
Image ’Splash’, 256 x 256. PSNR against numbet of segments.
27

26

25
Dyadic+Wedgelet
Dyadic+Wedgelet+Arclet
24
PSNR

23

22

21

20
0 100 200 300 400 500
Number of pieces

Figure 3.7: Plot for image ’splash’ : PSNR against number of segments for a
wedge model (red) and combination of wedge and arclet model(blue)

Image ’Obelix’, 253 x 341. PSNR against number of segments.


23

22.5

22
PSNR

21.5

Dyadic+Wedgelet
21 Dyadic+Wedgelet+Arclet

20.5

20
0 500 1000 1500
Number of pieces

Figure 3.8: Plot for image ’Obelix’ : PSNR against number of segments for a
wedge model (red) and combination of wedge and arclet model(blue)

52
Image ’Camera’, 256 x 256. PSNR against number of segments.
24

23.5

23

22.5
PSNR

22

21.5 Dyadic+Wedgelet
Dyadic+Wedgelet+Arclet

21

20.5

20
0 100 200 300 400 500 600
Number of pieces

Figure 3.9: Plot for image ’camera’ : PSNR against number of segments for a
wedge model (red) and combination of wedge and arclet model(blue)

Image ’Barbara’, 256 x 256. PSNR against Number of segments.


24

23.5

23

22.5
PSNR

Dyadic+Wedgelet
22
Dyadic+Wedgelet+Arclet

21.5

21

20.5

20
0 100 200 300 400 500 600
Number of pieces

Figure 3.10: Plot for image ’barbara’ : PSNR against number of segments for a
wedge model (red) and combination of wedge and arclet model(blue)

53
We observe PSNR from arclet scheme for over all images is approximately
increased +0.1 to +0.3 when compare to PSNR of wedgelet scheme. Totally, the
efficiency is small for image ’barbara’ than for image ’camera. This is due to the
qualitative of ratios influence for the image contents. Image’ barbara’ contains
much more texture, for while we can not expect to do much better by further of
the geometrical scheme.

54
Figure 3.11: Image ’bird’, 256 x 256. segmentation with a dyadic square model,
wedge model(180 angles) and arc model (32 possible center points of circles.γ =
0.01

55
Figure 3.12: Image ’circles’, 256 x 256. segmentation with a dyadic square model,
wedge model(180 angles) and arc model (32 possible center points of circles.
γ = 0.001

56
Figure 3.13: Image ’camera’, 256 x 256. segmentation with a dyadic square
model, wedge model(180 angles) and arc model (32 possible center points of
circles. γ = 0.01

57
Figure 3.14: Image ’obelix’, 256 x 256. segmentation with a dyadic square model,
wedge model(180 angles) and arc model (32 possible center points of circles.
γ = 0.01

58
Figure 3.15: Image ’peppers’, 256 x 256. segmentation with a dyadic square
model, wedge model(180 angles) and arc model (32 possible center points of
circles. γ = 0.01

59
Figure 3.16: Image ’splash’, 256 x 256. segmentation with a dyadic square model,
wedge model(180 angles) and arc model (32 possible center points of circles.
γ = 0.01

60
Figure 3.17: Image ’barbara’, 256 x 256. segmentation with a dyadic square
model, wedge model(180 angles) and arc model (32 possible center points of
circles. γ = 0.01

61
The performance of arclet scheme can improve PSNR values when compare
with the wedgelet scheme. We observe, however that the improvement of the
PSNR values is not a large as we could expect. We may give some possible
explanations to this phenomenon.

• Natural images contain not only a single arc line, but mostly arcs in the
image having width itself, a thick curve. The arclet decomposition attempts
to do more partitions to find the optimal arcs.

• Normally there are shading effect at the boundary of object in image. It is


not only a single line which represents the outline of object.

To overcome these problems we implemented a generization scheme, the so


called ringlet approximation scheme. This consists in allowing more complex
partition over each square. Normally, we allow two arcs in each square, which
lead to partition of this square in three pieces ( outside of the biggest circle, inside
of the biggest circles between both circles.) in figure 3.18 we display the distortion
rates for 3 scheme, dyadic , wedge and ringlet.

Image ’Bird’, 256 x 256. PSNR against number of segments.


34

Dyadic+Wedgelet
32 Dyadic+Wedgelet+Arclet
Dyadic+Wedgelet+Ringlet

30
PSNR

28

26

24

22
0 200 400 600 800 1000
Number of pieces

Figure 3.18: the plot shows the improvement of PSNR values with ’ringlet’
scheme.

The improvement of distortion rates with ringlet scheme can be observed with
up to +0.5 Db. which is satsfied.

62
Figure 3.19: Image ’bird’, 256 x 256. segmentation with a dyadic square model,
wedge model and ringlet model

63
Figure 3.20: Image ’splash’, 256 x 256. segmentation with a dyadic square model,
wedge model and ringlet model

64
Appendix: Original Images

Figure A.1: 256 x 256 Barbara

65
Figure A.2: 256 x 256 Bird

Figure A.3: 256 x 256 Camera

66
Figure A.4: 256 x 256 Circles

67
Figure A.5: 256 x 256 Obelix

68
Figure A.6: 256 x 256 Peppers

Figure A.7: 256 x 256 Splash

69
Bibliography

[1] G. Casella and C.P. Robert, Monte Carlos Statistical Methods, Springer
Texts in Statistics, Springer-Verlag, 1999.

[2] L. Demaret, F.Friedrich and H.Fuehr, A Quick guide to wedgelets, GSF Re-
search Center for Environment and Health, January 28,2005.

[3] L. Demaret, F.Friedrich and H.Fuehr, Beyond wavelets:New image represen-


tation paradigms, IBB Institute of Biomathematics and Biometry, 2005.

[4] D.L. Donoho, Wedgelets: Nearly minimax estimation of edges, Annuals of


Statistics, 27,(3):859-897, 1999.

[5] Y. Fisher, Fractal Image Compression: Theory and Application, Springer-


Verlag,1995.

[6] F. Friedrich, Complexity Penalized Segmentations in 2D.Phd thesis, Munich


University of Technology,2005.

[7] F. Friedrich, ANTSINFIELDS: Stochastic simulation and bayesian inference


for gibbs fields, Springer electronic media,2003.

[8] W. R. Gilks, S.Richardson, and D.J. Spiegelhalter, Markov Chain Monte


Carlo in Practice; Interdisciplinary Statistics, Chapman & Hall,1996.

[9] R. C. Gonzalez, R. E.Woods, Digital Image Processing, 2nd Edition 2002.

[10] P. A. Griffith, Intoduction to Algebraic Curves, Translations of mathematical


monographs; vol.76, 1989.

[11] M. D. McLLroy, Best Approximate Circles on Integer Grids , ACM Trans-


actions on Graphics, Vol.2, No. 4, October,1983.

[12] E. W. Nikitin, Into the Realm of Oberon: An Introduction to Programming


and the oberon-2 Programming Language, Springer-Verlag,1998.

70
[13] G. Sawitzki, Extensibible Statiscal Software: On a Voyager to Oberon,
J.Computational and Graphical Statist, 5(3):263-283, 1996.

[14] C. Szyperski, Component Software: beyond object-oriented programming,


AMC Press in co-operation with Addison-Wesley,1998.

[15] L.N. Trefethen and D.Bau., Numerical Linear algebra, SIAM, Philadephia,
Pennsylvania,1997.

[16] Katrin Wicker, Diploma thesis : Das Potts-Modell zur segmentation ver-
rauschter Daten, Munich University of Technology, 2004

[17] R.M. Willett and R.D. Nowak, Platelets: a multiscal approach for recover-
ing edges and surfaces in photon-limited medical imaging, IEEE Transac-
tions on Medical Imaging, 22:332-350, 2003.

[18] G. Winkler, Image Analysis, Random Fields and Markov Chain Monte Carlo
Methods,Applications of Mathematics; Vol.27, 2nd Edition,Springer,2002.

[19] Wedgelets website:, http://www.wedgelets.de

71
Abstract

This thesis is concerned with efficient algorithms for the segmentation of images
using so-called ”arclets”, a geometry-based approach. Arclets are an extension
of quadtree approximation allowing to include curved edges. We design fast and
flexible algorithms to compute arclet approximations of digital images.
Arclet approximation relies on quadtree structure. A criterion for the choice
of segmentations is given by minimization of a complexity penalised functional
over dyadic arclet partitions. Due to the structure of the functional, this problem
can be reduced to the computation of local approximation errors. We develop new
algorithms for the efficient computation of the local approximation errors.

You might also like