Digital Geometry: Contour Analysis§

author:David Coeurjolly

Contour representation§

Contour Encoding§

Objectives

Freeman Chain Code§

Idea

Starting point + differential code according to adjacency displacement and an orientation

_images/freeman.png _images/codage_freeman.png

Example§

_images/codage_freeman_bis.png

P_0=(2,1),\, C=\{2,1,0,1,0,7,7,6,5,4,3,5,4,3\}

Properties§

Reversible and unique encoding

Code driven geometrical transformations

Basic length estimator

Properties (Ctd.)§

Given a (1)-adjacency, let n_i be the number of ith-code

Path is closed iff

n_i = n_{i+2\,mod(4)}

(but may be self-intersecting)

Representation as a word on an alphabet

W=\{a,b,\bar{a},\bar{b}\}

A Polyomino P tiles the plane if and only if its contours has the following structure (up to cyclic rotations) X\cdot Y\cdot Z\cdot \bar{X}\cdot \bar{Y}\cdot \bar{Z} [Beauquier-Nivat]

_images/nivat.png

Fundamendal Objets: DSS§

Digitization based definition§

Given a digitization model:

Def.

A digital straight line (resp. segment) is the result of a digitization and an Euclidean line (resp. segment)

First Historical Construction§

Digital Segment tracing by Bresenham’s algorithm

GIQ based definition: For each abscissa we consider the closest grid point

_images/bresenham.png

Incremental construction

Properties

Implementation details§

Segment between (x_1,y_1) and (x_2,y_2) in \mathbb{Z}^2 with slope in [0,1]

Naive approach

y = y_s
for(i = x_1; i <= x_2; ++i)
   display(i,y);
   y_real = (y_2-y_1)/(x_2-x_1) * (i+1) + y_1;
   dy = y_real - y;
   if ( dy > 0.5)
     y++;

Integer only implementation§

e = x_2 - x_1
dx = 2*e
dy = 2*(y_2 - y_1)
while (x_1 < x_2)
  display(x_1,y_1);
  x_1 ++;
  e  -= dy;
  if (e <= 0)
     y_1 ++;
     e += dx:

Rationale

First arithmetical results§

Let us consider GIQ digitization scheme (similar to Bresenham’s) and a straight line y=ax +b with 0\leq a \leq 1. Let S be the digitization of the straight line and C its Freeman code

Thm

\exists p,q\in\mathbb{Z}, a=\frac{p}{q} \Leftrightarrow\text{ C is periodic with minimal period  }  \frac{q}{gcd(p,q)}

<demo>

_images/bresenham2.png

Example§

_images/exemple_droite.png

Periodic structure \rightarrow canonical pattern

Euclid’s Axioms§

Any two points define a unique straight line

_images/euclide1.png _images/euclide2.png

Two non-parallel straight lines intersects at a single point

_images/ex_inter_1_pt.png Single point
_images/ex_inter_vide.png Empty set
_images/ex_inter_non_connexe.png Non-connected set
_images/ex_inter_connexe.png Connected set

Euclid’s Axioms (bis)§

\Rightarrow we need to redefine parallelism, intersections, …

Switching to another digitization scheme, we may avoid some situations.

E.g. with analytical models, empty set case will never occur

DSS Characterizations§

Chordal Property [Rosenfeld]

Def.

\forall p \forall q\text{ and }\forall m\in[pq]\text{, there exists M(i,j) such that }\max(|i-x|,|j-y|)<1

_images/corde.png

Evenness Property [Veelaer]

Def.

\forall a,b,c,d\in[pq] \text{ such that }\vec{ba}_x=\vec{dc}_x,\, |\vec{ba}_y-\vec{dc}_y|=1

_images/evenness_prop.png

Diophantine Equations§

Definition

Def.

Diophantine equation = Equation with integer parameters and solutions in \mathbb{Z}

Example

ax + by = c

(with a,b,c\in\mathbb{Z} )

What is the general form of solutions of such linear diophantine equation ?

Solving Linear Diophantine Equation§

ax + by = c, and let S denote the solutions

Existence

S\neq\emptyset \Leftrightarrow gcd(a,b) | c

Homogeneous case

ax+by=0 \Rightarrow S=\{(-bk,ak), k\in\mathbb{Z}\}

General case

a' = \frac{a}{gcd(a,b)},\, b'=\frac{b}{gcd(a,b)},\, c'=\frac{c}{gcd(a,b)}

a'x + b'y = c'

Since gcd(a',b')=1, \exists u,v\in\mathbb{Z} such that a'u +b'v = 1 [Bezout]

\Rightarrow S=\{(uc' - b'k, vc' + a'k), k\in\mathbb{Z}\}

Your turn: 12x+15y=51

Analytical DSS§

Idea Design a analytical definition instead of combinatorial ones

Def.

S\subset\mathbb{Z}^2 is a analytical DSS with parameters (a,b,\mu,\omega)\in\mathbb{Z} with gcd(a,b)=1, if for all (x,y)\in S, we have

0 \leq ax -by + \mu < \omega

Illustration§

_images/droite_cont.png

Illustration§

_images/droite_cont_1.png

Illustration§

_images/droite_cont_2.png

Illustration§

_images/droite_cont_3.png

Illustration§

_images/droite_cont_4.png

Connectivity§

Thm.

D(a,b,\mu,\omega)

  • If \omega < \max(|a|,|b|), D is not a (k)-path
  • If \omega = \max(|a|,|b|), D is a (0)-arc
  • If \omega = |a|+|b|, D is a (1)-arc
  • If \max(|a|,|b|) < \omega < |a|+|b|, D is (*)-connected
  • If \omega > |a|+|b|, D is thick
_images/3_7_0_5.png _images/3_7_0_7.png _images/3_7_0_8.png _images/3_7_0_10.png _images/3_7_0_16.png
D(3,7,0,5) D(3,7,0,7) D(3,7,0,8) D(3,7,0,10) D(3,7,0,16)

Periodicity§

Thm.

Given D(a,b,\mu,\omega), D is invariant by translation with vector k.(b,a)^T (k\in\mathbb{Z})

<proof>

Corollary

Coro.

Any sequence of b pixels defines a DSS pattern, the pattern is minimal iff gcd(a,b)=1

Similar results than the one obtained by straight segment digitization but more generic

Toward stronger arithmetical results on DSS§

Farey Series§

Def.

The Farey Series \mathcal{F}_m of order m is the ordered sequence of irreducible fractions with denominator less or equal to m

e.g.:

\mathcal{F}_5=\left       \{\frac{0}{1},\frac{1}{5},\frac{1}{4},\frac{1}{3},\frac{2}{5},\frac{1}{2},\frac{3}{5},\frac{2}{3},\frac{3}{4},\frac{4}{5},\frac{1}{1}\right \}

Properties

\mathcal{F}_6=\left    \{\frac{0}{1},{\bf         \frac{1}{6}},\frac{1}{5},\frac{1}{4},\frac{1}{3},\frac{2}{5},\frac{1}{2},\frac{3}{5},\frac{2}{3},\frac{3}{4},\frac{4}{5},{\bf \frac{5}{6}},\frac{1}{1}\right \}

Stern-Brocot Tree§

_images/Sternbrocot.png

Binary search tree on \mathcal{F}_m fractions

Composition of DSS pattern§

Given

Then

\Rightarrow C_1C_2 is the Freeman code of one period of the DSS with slope \frac{u_1+u_2}{v_1+v_2}

Illustration§

_images/sternfreeman.png

All patterns: applications to DSS pattern intersection§

_images/stern-brocot_motifs-res.png

All patterns: applications to DSS pattern intersection§

_images/stern-brocot_chemin1-res.png

All patterns: applications to DSS pattern intersection§

_images/stern-brocot_chemin2-res.png

All patterns: applications to DSS pattern intersection§

_images/stern-brocot_chemin3-res.png

All patterns: applications to DSS pattern intersection§

_images/stern-brocot_chemin4-res.png

All patterns: applications to DSS pattern intersection§

_images/stern-brocot_chemin5-res.png

All patterns: applications to DSS pattern intersection§

_images/stern-brocot_chemin6-res.png

All patterns: applications to DSS pattern intersection§

_images/stern-brocot_chemin_dte2-res.png

All patterns: applications to DSS pattern intersection§

_images/stern-brocot_2dtes_bis-res.png

All patterns: applications to DSS pattern intersection§

_images/pattern2.png

Object Recognition§

Recognition Algorithm§

Idea

Given a digital set S, and a geometrical primitive (DSS, Digital circle, digital plane, …), decide if S is a subset of such primitive

Useful to

Geometrical Recognition (1)§

Idea

Revert the digitization process and solve a dual problem

DSS: Linear dual space

_images/esp_param1-res.png _images/esp_param2-res.png _images/esp_param3-res.png

Geometrical Recognition (2)§

Let us consider the following OBQ digitization scheme of l: ax - by + \mu=0

_images/droite_OBQ-res.png

Each pixel (x_0,y_0) contributes to two linear constraints:

0  \leq \alpha x_0 - y_0 + \beta < 1

_images/pixel_OBQ-res.png _images/dual_OBQ-res.png

Geometrical Recognition (3)§

Algorithm principle

Given a set S of pixels

\Rightarrow if \bar{S} is empty, S is not a DSS (for OBQ scheme)

\bar{S} is called the preimage of S

Example§

_images/dual_pixels1-res.png _images/dual_naive1-res.png

a=(2,2) , D_a: 2\alpha - 2+\beta=0 and D'_a: 2\alpha - 2+\beta=1

Example§

_images/dual_pixels2-res.png _images/dual_naive2-res.png

b=(4,3) , D_b: 4\alpha - 3+\beta=0 and D'_b: 4\alpha - 3+\beta=1

Example§

_images/dual_pixels3-res.png _images/dual_naive3-res.png

c=(8,4) , D_c: 8\alpha - 4+\beta=0 and D'_c: 8\alpha - 4+\beta=1

Example§

_images/dual_pixels4bis-res.png _images/dual_naive4bis-res.png

d=(9,5), D_d: 9\alpha - 5+\beta=0 and D'_d: 9\alpha - 5+\beta=1

Example§

_images/dual_pixels_final-res.png _images/dual_naive_final-res.png

p=\left(\frac{1}{3},2\right) in the dual space leads to l: \frac{1}{3}x -y +2 = 0

Computational cost§

Preimage = Classical linear programming problem

If S is a (0)-path

Thm. \bar{S} has at most 4 vertices in the dual space

_images/structure_ilroy.png

\Rightarrow On-line DSS recognition in O(n) (O(1) per constraint)

Algorithm§

_images/preimage-algo.png

Rationale of the preimage structure§

Farey Fan

The Farey Fan of order n is a decomposition of the space into cells where each cell corresponds to a DSS preimage of length n+1

_images/farey_fan_2.png _images/farey_fan_3.png _images/farey_fan_6.png
Order 2 Order 3 Order 6

DSS and Farey Fan Cell§

_images/fareyfan5.png

Arithmetical Recognition§

Idea

Use the analytical representation of DSS:

Definitions (again)

Defs.

  • (x,y) is exterior to D if its reminder is lesser than \mu-1 or greater than \mu+b
  • (x,y) is weakly exterior to D if its reminder is equal to \mu-1 or \mu+b
  • The net with order \mu is the upper leaning net
  • The net with order \mu+b-1 is the lower leaning net

Illustration§

_images/reveilles_appui.png

Main Recognition Theorem§

Let U (resp. U’) be the upper leaning point with minimal abscissa (maximal abscissa) and L (resp. L’) be the lower leaning point with minimal abscissa (maximal abscissa)

Given a DSS digital set S w and a point M (with reminder r), we have to decide if S\cup\{M\} is still a DSS

Thm.

  • if \mu \leq r < \mu+b then S\cup\{M\} is a DSS with parameter D(a,b,\mu)
  • if M is exterior, S\cup\{M\} cannot be a DSS
  • if M is weakly exterior with r=\mu+1, S\cup\{M\} is a DSS where the slope is given by \vec{UM}
  • if M is weakly exterior with r=\mu+b, S\cup\{M\} is a DSS where the slope is given by \vec{LM}

At each step, we maintain/update U,U’,L,L’ and DSS parameters a,b, \mu

Theorem cases§

_images/algo_debled.png

Algorithm§

_images/debled-algo.png

Analysis§

Computational cost

Key point of the proof: unimodular vectors

Given two vectors \vec{u},\vec{v}\in\mathbb{Z}^2, \vec{u} and \vec{v} are unimodular iff det(u,v) \pm 1

E.g. \vec{UU'} and \vec{UM} are unimodular if M is weakly superior

(if vectors define fractions, fractions are neighbors in a given Farey series)

Unimodular means that there is no integer point in the parallelogram (\vec{u},\vec{v})

_images/unimodular.png

Example§

_images/algo_debled_run.png

Digital Plane§

Similar approaches

_images/plan_fin.png _images/plan_naif.png _images/plan_stand.png
P(6,13,27,0,15) P(6,13,27,0,27) P(6,13,27,0,46)

General Approach for Recognition Algorithm Design§

Digitization -> Constraints

Given the primitive (plan, circle, …), digitization usually implies inequality system we have to solve

Usually:

Regularity/arithmetic in analytical representation

Design the recognition as a separation problem with tools from Computational Geometry

In practice: a kind of mix between all these approaches…

Contour Polygonalization§

Contour Decomposition into maximal DSS§

Idea

Starting from a contour point (and given a direction), decompose the contour into maximal DSS adding pixels one by one

_images/cercle_segm.png _images/carre_segm.png _images/sinc_segm.png

\Rightarrow O(n) algorithm

\Rightarrow Changing the starting point, decompositions differs by one (N, N+1)

In 3D…§

Similar approach but

  1. No trivial order
  2. Heuristic to scatter seeds for the incremental recognition
  3. Parallel or sequential process

Usually

_images/al.png _images/dodgePlans.png

Back in 2D: Polygonalization problem§

Principle

Convert a digital contour into a polygon such that its digitization is the input digital set

First approach: use DSS decomposition

Indeed, DSS segments are “reversible” … but not the vertices..

_images/contre_ex_methode_naive_2D.png _images/revproblem.png

\Rightarrow We need to constraint the preimages to ensure that successive DSSs have euclidean representative segment with “reversible” intersection vertex

Example of a solution in 2D§

_images/pixels_courbe0-res.png

Example of a solution in 2D§

_images/pixels_courbe0bis-res.png

Example of a solution in 2D§

_images/pixels_courbe-res.png

Example of a solution in 2D§

_images/pixels_courbe3-res.png

Example of a solution in 2D§

_images/pixels_courbe4-res.png

Reversible reconstruction in dimension 3§

More difficult because of topological issues.

Idea: start from a topologically valid reversible triangulation (Marching Cubes), merge triangles using digital plane decomposition information and constraints on preimage

_images/resultats.png

(Marching Cubes)§

_images/MC.png _images/spheremc.png