bachelor thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. the...

55
Bachelor Thesis Mathematical Methods of Image Processing to Characterize Micro Cups John Wilfried Schlasche July 26, 2011

Upload: others

Post on 15-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Bachelor Thesis

Mathematical Methods of Image Processingto Characterize Micro Cups

John Wilfried Schlasche

July 26, 2011

Page 2: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Contents

Introduction 1

0.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1 The Perona-Malik Equation 4

1.1 The Idea Behind this Approach . . . . . . . . . . . . . . . . . . . . . . . . 4

1.1.1 Partial Differential Equations . . . . . . . . . . . . . . . . . . . . . 4

1.1.2 PDEs in Image Processing . . . . . . . . . . . . . . . . . . . . . . . 5

1.1.3 How to Find the Appropriate Equation? . . . . . . . . . . . . . . . 6

1.1.4 The Perona-Malik Diffusion Equation . . . . . . . . . . . . . . . . . 6

1.2 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.2.1 Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.2.2 Existence and Uniqueness . . . . . . . . . . . . . . . . . . . . . . . 9

1.3 Numerical Implementation and tests of the PM-Method . . . . . . . . . . . 16

1.3.1 Which Approach is Used? . . . . . . . . . . . . . . . . . . . . . . . 16

1.3.2 What Problems May/Did Occur . . . . . . . . . . . . . . . . . . . . 19

1.4 Appliance to our Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

1.4.1 Application to Workpiece Data . . . . . . . . . . . . . . . . . . . . 20

1.4.2 Examples of the Problems that did Occur . . . . . . . . . . . . . . 22

2 Characterization 23

2.1 What information are we looking for? . . . . . . . . . . . . . . . . . . . . . 23

2.2 Parameters of the workpiece . . . . . . . . . . . . . . . . . . . . . . . . . . 23

2.2.1 Problems and Conditions Placed on the Image . . . . . . . . . . . . 25

2.3 Assessment of the Rim’s Characteristic . . . . . . . . . . . . . . . . . . . . 25

2.3.1 Application to our Measurement Data . . . . . . . . . . . . . . . . 27

2.4 Evaluating the Quality of the Workpiece’s Bottom . . . . . . . . . . . . . . 28

2.4.1 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

2.5 How to Find Cracks in the Rim . . . . . . . . . . . . . . . . . . . . . . . . 30

Appendix 30

Page 3: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

A Further Tests 31A.1 Test1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31A.2 Test2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

B Source Code 37B.1 Source Code of the Perona-Malik Diffusion . . . . . . . . . . . . . . . . . . 37B.2 Source Code of the Parameter Search . . . . . . . . . . . . . . . . . . . . . 41B.3 Source Code of the Edge Characterization . . . . . . . . . . . . . . . . . . 46B.4 Smoothing the Edge Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 48B.5 Source Code of the Form Assessment . . . . . . . . . . . . . . . . . . . . . 49

Bibliography 51

3

Page 4: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Introduction

In a micro deep drawing process a thin metal sheet is fixated under a punch,which then draws the sheet into the required form. Especially during the pro-duction of very small parts, many unanticipated manufacturing errors such ascracks, wrinkles, defects of form and chip formation may occur.In order to minimize these flaws, the resulting parts have to be characterizedand the parameters changed accordingly. To get the characterization done inreasonable time, a laser scanning microscope is used, but since the obtainedimage data of the micro parts are mostly very noisy, characterization becomesexceedingly complicated.The characterization consists of two main steps of procedure. First the ”im-portant” edges in the data have to be found and secondly the micro part itselfand its flaws have to be found and classified.

1

Page 5: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Figure 1: Keyene VK 9700 3D Laser microscope [13]

During the first part of the process the usage of standard algorithms suchas Sobel edge detection connected with standard smoothing, leads to seriousproblemssuch as:

The shape found in the edge image might not be the original one due toedge displacement.

It might be impossible to distinguish between noise and real edges in theimage (noise may be far stronger represented than important edges offissures).

Even if the noise is reduced sufficiently there may be far too many edgesto make a definite statement about the quality of the micro part.

The first subject of this thesis is the application of the Perona-Malik diffusionto this problem. The idea behind this smoothing algorithm is to use a certainpartial differential equation instead of solely applying filters to the image.The second part of the thesis deals with possible ways to characterize theworkpieces based on the resulting image data.

2

Page 6: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

0.1 Notation

t Time variable

x Space-variable

u=u(t,x), v=v(t,x) Function of real or complex value. If not stated otherwise,they are defined on Ω (Usually this denotes our image-data).

Ω ⊂ Rn Open and bounded domain with smooth boundaries ∂Ω

A,B,C Matrices

ai,j, bi,j, ci,j ∈ C or R Entries of the matrices above

g = g(x) Function with domain [0,∞] (generally the diffusivity function).

φ ∈ C∞0 (Ω) (or ∈ H1,20 (Ω)) Test function

∂s The partial differential operator for the multindex s∂2u∂x1x2

= u1,2 if it is clear that (·)i is no indexing∂2u∂x1x2

= ux1,x2 Otherwise

W k,p(Ω) , k ∈ N = u ∈ Lp(Ω)|Dsu ∈ Lp(Ω)∀s : |s| ≤ kThe Sobolev space (Ds denotes the weak derivative)

W k(Ω) = W k,2(Ω) note that this is a Hilbert space [5]

X(Ω) A function space (mostly W 1(Ω) or its dual W 1∗(Ω))

Lp([0, T ];X) = u(t, x)|∀t ∈ [0, T ] : u(t, ·) ∈ X and (∫ T

0||u(t)||Xdt)1/p

∂u∂n

Mostly used to denote the flow of the function u across the Border of Ωwhere n is the normal of ∂Ω

3

Page 7: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Chapter 1

The Perona-Malik Equation

1.1 The Idea Behind this Approach

In this chapter important concepts which help to understand and in a way lead to thePerona-Malik algorithm are introduced.

1.1.1 Partial Differential Equations

As we will come to see, he theory of partial differential equations (short: PDEs) is ofgreat importance in this work and a short introduction is therefore given at this point.Theoretical results including existence and uniqueness are given in Chapter 2. Generallya PDE is an equation or a system of equations which include the partial derivatives of anunknown function u of more than one independent variable.Important examples are:

1. The linear wave-equation: ∂2u∂t2−c2∆u(t, x) = 0 whose solution, for c = speed of light,

is the electro-magnetic wave.

2. The heat equation ∂u∂t−∆u = 0.

3. The Laplace equation ∆u = 0 which describes all harmonic functions such as elec-tromagnetic potentials in the static case.

Most PDEs are much more complex than the examples given above and unlike ordinarydifferential equations (ODEs) there are no simple conditions that ensure the existence anduniqueness of a solution.PDEs can be categorized into the three groups elliptic, parabolic and hyperbolic PDEs.The general definition is quite complicated and is in part to be found in section 1.2.2, see[8] for more details.In most cases it is sufficient to examine at the time-derivative in the equation:

• No time-derivative: Elliptic system,

4

Page 8: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

• Time-derivative of the first order: Parabolic system,

• Time-derivative of the second order: Hyperbolic system.

The most important examples happen to be the examples above. The wave-equation ishyperbolic, the heat-equation is parabolic and the Laplace-equation is an elliptic PDE.

1.1.2 PDEs in Image Processing

The concept of scale space is part of the axiomatic image processing and therefore amathematical way to:

Derive and prove features of certain algorithms used for image processing.

Create algorithms for image processing on the basis of properties postulated on im-ages.

For a fuller treatment of of scale space theory we refer the reader to [1] Chapter 4. Ingeneral, a multi-scale analysis is a family of transformations Ttt≥0 which defines a trans-formation for every t ≥ 0. In our case the idea is to neglect finer details of the originalimage for greater t. As an example, a tree might be seen with all its leafs and branches fort = 0. As t is increased, one can still recognize thicker branches but the leafs are blurred.For even greater t only the log and the treetop are distinguishable.This concept fits very well for this type of image processing where the goal is to ignore thenoise added by the camera, while preserving the general structure of the micro part.

Theorem 1.It is shown in [1] that if a multiscale analysis fulfills following requirements:

1) Translation-invariance: (T (u(·+ x′)))(x) = (T (u))(x+ x′)

2) Monotony: u ≤ v ⇒ Ttu ≤ Ttv

3) Invariance with respect to gray scale shifting

4) Regularity: ||Tt(u+ hv)− Ttu− hv||∞ is bounded

5) Recursiveness: Ts(Tt(u)) = Ts+tu

6) Locality: (Ttu)(x) only depends on the values of u(.) near x

Then there exists a continuous functions F (·, ·, ·) such that

∂u

∂t(t, x) = F (x, u(t, x),∇u(t, x),∇2u(t, x)) ,

where ∇2 is the Hessian matrix.

These requirements are fulfilled by quite a wide range of image processing algorithms.Indicating that there may be a way to define an algorithm which fits our needs, using PDEs.

5

Page 9: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

1.1.3 How to Find the Appropriate Equation?

The Gaussian filter seems the most obvious approach, for it surely eliminates most of the

noise. Smoothing a signal u0(x) with the Gaussian kernel in 2D (Gσ(x) = 12πσ2 e

− |x|2

2σ2 ) isthe same as solving the Heat-equation

∂u

∂t= c∆u(t, x) = div(c∇u(t, x))

for u(0, x) = u0(x) and t = σ.This equation can be derived using firstly Fourier’s law and secondly the enegergy conser-vation law.Fourier’s law states that the flow rate of any concentration or heat energy is proportionalto the negative gradient of the concentration or the temperature respectively;

ju(t, x) = −k∇u(t, x) k ∈ R (in the isotropic case, k is constant),

where ju denotes the flow of u and isotropic means that the diffusion is independent of x.The energy conservation law or the the mass conservation law states that the change inenergy or mass in a domain equals the flow across its border. Combined with partial inte-gration this is where the div(·) stems from.

Nevertheless, the diffusion equation in this form is not applicable for it moves and even-tually eliminates all edges and thereby changes the outcome of the characterization in anundesired way.

1.1.4 The Perona-Malik Diffusion Equation

To adapt the diffusion equation to our needs, a so-called anisotropic diffusion, where theflow is not only proportional to the gradient, but is also controlled by a function g(|∇u|),is used. Regions with low |∇u| are plains. By choosing a high diffusion coefficient thenoise can be reduced. Regions with high |∇u| can be found near edges. In order for thoseedges to be preserved (or even enhanced as we will see), a low diffusion coefficient is chosenaccordingly. This leads to the function

g : [0,∞] 7→ [0, 1], g(0) = 1, lims→∞

g(s) = 0 monotonically decreasing.

In order to obtain a complete system, which is needed to solve the equations, boundaryconditions also have to be defined. As is common in image processing the Neumannboundary condition n ·∇u = 0 on ∂Ω is used. This ensures that there is no flow across theboundary and the overall brightness is thereby preserved. This lead to following system of

6

Page 10: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

equation:

∂u

∂t= div(g(|∇u|)∇u) on Ω (1.1)

n · ∇u = 0 on ∂Ω with n = normal of ∂Ω (1.2)

u(0, x) = u0(x) on Ω (1.3)

1.2 Theory

1.2.1 Behavior

To get a first overview of what the Perona-Malik diffusion does, we convert the right sideof equation (1.1) by using div(g · ~f) = ∇g · ~f + div(~f)g and div(∇u) = ∆u.

div(g(|∇u|)∇u) = ∇(g(|∇u|)) · ∇u︸ ︷︷ ︸∗

+g(|∇u|)∆u.

The term (*) can be transformed even further:

∇(g(|∇u|)) · ∇u =g′(|∇u|)|∇u|

(u1u1,1 + u2u2,1, u1u1,2 + u2u2,2) · ∇u

=g′(|∇u|)|∇u|

(u21u1,1 + u2u1u2,1, u1u2u1,2 + u2

2u2,2).

⇒ div(g(|∇u|)∇u) =g′(|∇u|)|∇u|

∇uTH(u)∇u+ g(|∇u|) ·∆u , (1.4)

where H(u) is the Hessian matrix.To analyze the behavior of this, we now take a closer look at the edges in our image:In 2 dimensions (which is what we’re dealing with) we can (locally) define two coordinates:

• η := ∇u|∇u| which is the direction of greatest decrease/increase. In the vicinity of an

edge, this is orthogonal to the edge.

• ν is defined to be an orthogonal to η with ||ν|| = 1 (near an edge there always existssuch a η), this is parallel to the edge.

Note that the Laplace-operator ∆ is rotation invariant and therefore the same for everyorthonormal basis:

∆u =∂2u

∂e21

+∂2u

∂e22

=∂2u

∂η2+∂2u

∂ν2

where e1 = (1, 0)T , e2 = (0, 1)T . Using all this the equation (1.4) can be written as follows:

div(g(|∇u|)∇u) = (g′(|∇u|)|∇u|+ g(|∇u|))uη,η + g(|∇u|) (∆u− uη,η)︸ ︷︷ ︸=uν,ν

.

7

Page 11: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

In this notation the equation is split into a term which describes the diffusion along theedge and one which describes the diffusion orthogonal to the edge.If we define the function f as f(s) := s · g(s) we can shorten the equation even further,and obtain

div(g(|∇u|)) = f ′(|∇u|)uη,η + g(|∇u|)uν,ν . (1.5)

In this form, one can already see that there might be something resembling backward dif-fusion if f ′(|∇u|) is of negative value and uηη >> uνν which is the case near edges.Backward diffusion means that unlike normal diffusion, which eventually smooths every-thing, the Perona-Malik diffusion may indeed not only preserve strong edges but alsoenhance them.

Theorems on the Behavior of the Perona-Malik algorithm in one Dimension

The following theorems deal with the behavior of the Perona-Malik (P-M) diffusion nearedges in one dimension and are taken from [1] and [2].They can to some extend be applied to 2D, since as we have seen we can locally considerthe orthonormal basis η, ν in which η is the most “important” direction. To put it moregraphically: We can (locally) look at slices of the original image and treat them as onedimensional signals.

Definition 1. We say that u ∈ C3(R,R) has an edge in x if:

|u′(x)| >> 0 (An edge is always an area of big change in the signal),

u′′(x) = 0 (the edge is a point, not a whole area),

u′(x)u′′′(x) < 0.

The last point guarantees that |u′| is locally maximal in x, this can best be understoodby looking at an example:If u′ is of positive value we have a local maximum of u′ in x if u′′ > 0 to the left of xand u′′ < 0 to the right. Together with the second condition this can be expressed byu(x)′′′ < 0. The case for u′ < 0 follows analogously.

Theorem 2. Theorem on edge-behaviorThe notation ∂1u

∂η= uη ,

∂2u∂η2

= uη,η is used here.

Let u(t, x) denote a strong solution for the Perona-Malik equation on [0, T ] × Ω withu(0, x) = u0. Suppose u(t, ·) ∈ C5(R,R)∀t ∈ [0, T ] and u(·, x) ∈ C1(R,R)∀x ∈ Ω.

8

Page 12: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Let x denote the position of an edge in u0 where in addition to the definition aboveu′′′′0 (x) = 0 then :

∂tuη = f ′(uη)uη,η (1.6)

∂tuη,η = 0, (this ensures that inflection points are preserved) (1.7)

∂t(uηuη,η,η) = 3f ′′(uη)uη,η,η uη,η,ηuη︸ ︷︷ ︸<0

+f ′(uη)uηuη,η,η,η,η + f ′(uη)u2η,η,η (1.8)

The first equation describes whether an edge is preserved, enhanced or reduced andthe second ensures that inflection points are preserved (meaning that if x is an edge pointbefore the application of the P-M algorithm, it still is one afterwards). The third equationlooks quite abstract but nevertheless it describes an important potential problem in the1D case of the Perona-Malik algorithm called staircasing: If ∂t(uηuη,η,η) > 0 it may be thecase that for some t ∈ [0, T ] uη(x)uη,η,η(x) > 0 which would mean that although we hada point of maximum |uη| to begin with it somehow changed to a point where |uη| is notlocally maximal.

Figure 1.1: Staircasing effect in one dimension [1].The left figure shows the function and the absolute value of its gradient, the right figureshows the function before and after the the Perona-Malik algorithm. The staircasing effectcan be observed on the leftmost edge, whose gradient is maximal.

We did not encounter Staircasing-effects in 2D in any of our Tests, this might be dueto our image-data or the chosen parameters. However these theorems show how importantthe choice of g is, by far not every decreasing function is appropriate. A wide range offunctions is introduced and analyzed in [2].

1.2.2 Existence and Uniqueness

So far we assumed that there is a unique solution for the Perona-Malik PDE, which isactually not obvious as the following example will show.

9

Page 13: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

As we know, in one dimension the equation has following form:

du

dt= (g′(u′)u′ + g(u′))u′′

with the definition f(s) = s · g(s) this can be converted to

du

dt= f ′(u′)u′′ ,

where f is symmetric and decreasing for greater |u′|. This can in approximation be writtenas

du

dt+ cu′′ = 0 , c > 0 ,

which is the inverse heat-equation. This equation is the inversion of smoothing, which givesus quite different results for almost identical starting values! (Note that this is not a proofthat all functions g(s), such that s · g(s) is decreasing for some values, are inappropriate.It is just an example why solvability and uniqueness is not a trivial issue.)

In this section we will take a short look at theoretical results on the solvability of ourequation, for only then can we be sure that our numerical outcome is reproducible at anytime.

Results for linear Parabolic Equation

Only the key idea of the proof is written down at this point, see [8] for the complete proof.

Definition 2. The differential operator of second orderLet [0, T ] ⊂ R≥0 be the time-interval then the PDE is defined as

∂u

∂t+ Lu = f on (0, T ]× Ω (1.9)

A∇u · n = 0 on (0, T ]× ∂Ω (1.10)

u(0, ·) = u0(·) on Ω , (1.11)

where L denotes the partial derivatives of u up to second order (see below), A∇u is theflow of u and n as before the normal of ∂Ω. In the notation we used before (uxi = ∂u

∂xi) L

has following form:

Lu =n∑i,j

(ai,j(t, x)uxi)xj +n∑i=1

bi(t, x)uxi + c(t, x)u .

Remark:A(t, x)i,j = ai,j and in the following we consider the case where A is symmetric.

10

Page 14: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Not every PDE has a unique solution, we therefore define the parabolic differentialoperator.

Definition 3.We say that the differential operator ∂u

∂t+Lu is uniformly parabolic if there exists a constant

Θ > 0 such that

n∑i,j

(ai,j(t, x)ξiξj) > Θ|ξ|2 ∀(t, x) ∈ [0, T ]× Ω, ξ ∈ Rn

Note that in our case the Perona-Malik equation becomes parabolic (not linear!) assoon as g(t, x) > c for a constant c > 0.

Weak solutions for parabolic PDEs are defined quite similar to weak solutions of ellip-tic PDEs [5] using differentiable test functions φ. As is introduced in [5] we define weakderivatives as ∫

Ω

∂sφu = (−1)|s|∫

Ω

φ∂su .

This can also be applied to the time-derivative:∫[0,T ]

φ′u = −∫

[0,T ]

φu′ .

In the following section u′ refers to the weak time derivative of the solution u .If we multiply (1.9) with a test function φ and integrate over Ω we get following equation:∫

Ω

u′φ+

∫Ω

∇ · (A∇u)φ+

∫Ω

b · ∇uφ+ cuφ =

∫Ω

Using partial integration over Ω and the fact that∫

ΩφA∇u · n = 0, the second term can

be rewritten as ∫Ω

A∇u · ∇φ .

We therefore define:

Definition 4. Weak solutionsLet u ∈ L2([0, T ];W 1(Ω)) and u′ ∈ L2([0, T ];W 1∗(Ω)). Then u is a weak solution of(1.9)-(1.11) if u solves

< u′, φ > +B(u, φ, t) =

∫Ω

f(t, .)φ(t, .) (1.12)

for almost every t ∈ [0, T ] and every test function φ ∈ H10 (Ω) = f |f ∈ H1(Ω) , supp(f) compact

andu(0, ·) = u0(·) on Ω , (1.13)

11

Page 15: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

where

< u′, φ > =

∫Ω

u′(t, ·)φ(t, ·) and

B(u, φ, t) =

∫Ω

A(t, ·)∇u(t, ·) · ∇φ(t, ·) +

∫Ω

b(t, ·) · ∇u(t, ·)φ(t, ·) + c(t, ·)u(t, ·)φ(t, ·) .

Using this definition of weak solutions we now study results on the existence and unique-ness of weak solutions for linear parabolic equations.

Theorem 3. ExistenceIf ai,j, bi, c ∈ L∞(Ω) independent of t, u0 ∈ L2(Ω) and ∀t ∈ [0, T ], f(t, ·) ∈ L2(Ω) thenthere exists a weak solution of the boundary value problem (1.9),(1.10),(1.11).

Proof.Due to its complexity, just a small overview of the proof is given at this point. We referthe reader to [8] for the whole proof.The general idea is, that we take a look at some finite dimensional subspace of W 1

0 (Ω),defined as Bn := span(wini=1) where wi∞i=1is the orthonormal basis of a dense subspaceof W 1

0 (Ω) (for examples of wi∞i=1 see [8] as well). For the finite dimensional case on Bn

the solution un can be represented by a linear combination of functions wi.If we also take our test functions from wini=1, (1.12) becomes a system of OrdinaryDifferential Equations which is uniquely solvable according to the Picard-Lindeloff Theorem[15] §12.It is then shown that for n = the dimension of B the sequences of solutions un ⊂L2([0, T ];W 1

0 (Ω)) and their derivatives u′n ⊂ L2([0, T ];W 1(Ω))∗ are bounded for n→∞.Since these spaces are Hilbert spaces there exists a convergent subsequence.Next it is ensured that the limit function u, whose derivative u′ is the limit function ofu′n∞n=1, is indeed a weak solution on the whole subspace with the basis wi∞i=1 where wechose the coefficients to be smooth functions (in t).Since the space span(wi∞i=1) is dense in W 1

0 (Ω) for every t ∈ [0, T ] the statement follows.

Following is a theorem which is needed to prove the uniqueness of found solution:

Theorem 4. Gronwalls inequalityLet f be a real-valued differentiable function and β a continuous function defined on [0,T].If f satisfies the differential equation

f ′(t) ≤ β(t)f(t) on (0, T ]

thenf(t) ≤ f(0)e

∫ T0 β(t) for all t ∈ [0, T ] .

12

Page 16: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Theorem 5. UniquenessThe weak solution of (1.9),(1.10),(1.11) is unique.

Proof.Again We only give a short sketch of the proof.Assume that u and v are both solutions to the same Problem, then u − v is obviously asolution for the same problem with f ≡ 0 and (u − v)0 ≡ 0. We therefore have to showthat only u ≡ 0 solves the Problem (1.9),(1.10),(1.11) with f ≡ u0 ≡ 0.Let φ = u on [0, T ] × Ω then we can exchange the integral and ∂

∂tin the first term of the

equation (1.12) to obtain

∂t(1/2||u||2L2(Ω)) = −B(u, u, t) ,

where B(u, u, t) is as in definition (4). We can estimate −B(u, u, t) to be ≤ γ||u||2L2(Ω) for

a constant γ, as is proven in [8].At this point we use Gronwalls inequality with f(t) := ||u(t, ·)||2L2(Ω) and β(t) = γ.

Since ||u0||2L2(Ω) = 0 this proves the statement.

Results for the Perona-Malik Equation

At first sight one might believe that these results for linear parabolic equations can bedirectly applied to the Perona-Malik equation but this is not the case, for here A(t, x) =g(∇u(t, x)) which results in a non-linear equation. We can nevertheless show existence anduniqueness for a slightly modified version of the P-M equation.The basis of the theorem on the existence is the Schauder-Tychonoff fixed point theorem.

Theorem 6.Remark: (The Version of the Schauder fixed point theorem we need here has been provedby Tychonoff in 1935 [9] and deals with topological Banach spaces instead of normed spacesas is the case in most versions found in books. We will later apply this to the weak topologyof our function space.)Let W be a closed and convex subset of a locally convex topological vector space S andE : W 7→ W a continuous mapping such that the range E(W ) is contained in a compactset. Then E has a fixed point.

For proof see [9]

The next Theorem is taken from [7] where the question of the regularity of u is dealtwith as well.

13

Page 17: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Theorem 7. Existence and uniqueness of a weak solution for the P-M equationLet g : R≥0 7→ R≥0 be a decreasing function with g(0) = 1, limt→+∞ g(t) = 0 and t 7→g(√

(t)) is smooth. For σ > 0 Gσ(x) := 1√2πσ

e−|x|24σ . Let now u0 ∈ L2(Ω). Then there

exists a unique function u(t, x) such that u ∈ C([0, T ];L2(Ω))⋂L2([0, T ];H1(Ω)) is a weak

solution of

∂u

∂t− div(g(|∇(Gσ ∗ u)|)∇u) = 0 on (0, T ]× Ω (1.14)

∂u

∂non (0, T ]× ∂Ω (1.15)

u(0, ·) = u0 . (1.16)

Proof.We will first prove the existence of a solution.Since the full proof is quite long, only the general outline of the one written down in [7] isgiven here.First we need to define a Hilbert space

W (0, T ) = w ∈ L2(0, T ;W 1(Ω))|∂w∂t∈ L2(0, t;W 1(Ω))∗

with the graph norm.We define the system of equation E(w)

∂u

∂t− div(g(|∇(Gσ ∗ w)|)∇u) = 0 on (0, T ]× Ω

∂u

∂non (0, T ]× ∂Ω

u(0, .) = u0 ,

which is a linear parabolic equation for every fixed w ∈ W (0, T )⋂L∞([0, T ];L2(Ω)) and

therefore has a unique solution (the equation is parabolic is parabolic since w is boundedand thus, g(|∇(Gσ ∗ w)|) > ε > 0).In [1] it is shown, that

||u(t, ·)||Lp(Ω) ≤ ||u0||Lp(Ω) p ∈ [2,∞]. (1.17)

The proof also holds for our slightly modified version where u is the solution to the problemwith g(|∇(Gσ ∗ w)|).Let U(w) be the solution for E(w) it is thereby shown that

||U(w)||L2([0,T ];H1(Ω)) ≤ C1 (1.18)

||U(w)||L∞([0,T ];H1(Ω)) ≤ ||uo||L2(Ω) (1.19)

||∂U(w)

∂t||L2([0,T ];H1(Ω)∗) ≤ C3 , (1.20)

14

Page 18: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

where the constants C1, C3 are solely dependent on G, g and u0

In the next step a subspace W0 of W (0, T ) is introduced which contains all functions wthat are bounded like our solution in equations (1.18),(1.19) and (1.20). The set W0 isnonempty and convex and obviously W0 is weakly compact in W (0, T ). Given that andthe fact that U(w) is a weakly continuous mapping W0 7→ W0 this allows us to use theSchauder fixed point theorem mentioned earlier.This ensures that there is a function u ∈ W0 such that u solves U(u). This proves theexistence of a solution to (1.14), (1.15),(1.16) .

To prove that the solution u is unique, we use a similar approach as we did in Theo-rem 5 for linear parabolic PDEs. Again only the general idea is given.If u and v are both solutions to (1.14)-(1.16) we can easily deduce that u and v solvefollowing equations:

∂(u− v)(t, ·)∂t

− div(gu(∇u(t, ·)−∇v(t, ·))− div((gu − gv)∇v(t, ·)) = 0 on (0, T ] ,

∂u

∂n=∂v

∂n=∂u− v∂n

= 0 on (0, T ]× ∂Ω ,

u0 − v0 = 0 on Ω

for gu = g(|∇Gσ ∗ u|) and gv = g(|∇Gσ ∗ v|). Multiplying this equation with (u− v) andintegration over Ω leads us to

1

2

∂t||u− v||2L2(Ω) −

∫Ω

(u(t, ·)− v(t, ·))div(gu(∇u(t, ·)−∇v(t, ·)))︸ ︷︷ ︸∗

=

∫Ω

(u(t, ·)− v(t, ·))div((gu − gv)∇v(t, ·))︸ ︷︷ ︸∗∗

.

By using partial integration combined with the boundary conditions the second term onthe left side can be transformed to

∗ =1

2

∂t||u− v||2L2(Ω +

∫Ω

(gu(∇u(t, ·)−∇v(t, ·))2)︸ ︷︷ ︸≥0

The right side is transformed in a similar fashion using in addition the Holder inequalityand can then be shown to be

∗∗ ≤ C||u− v||2L2(Ω)||∇u||2L2(Ω)||∇u−∇v||2L2(Ω)

for a Constant C. Where the term ||u − v||2L2(Ω) stems from estimating ||gu − gv||L∞(Ω) ≤C2||u− v||2L2(Ω) for some constant C2.

This proves the uniqueness since the Gronwall’s inequality (Theorem 4) is applicable with

15

Page 19: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

(u− v)(0, ·) = 0 and therefore (u− v) = 0.Remark: At this point the regularity of the soltion u is needed, since in (Theorem 4)β = 2C||∇u||2L2(Ω)||∇u−∇v||2L2(Ω) has to be a regular function.

1.3 Numerical Implementation and tests of the PM-

Method

1.3.1 Which Approach is Used?

Let u ∈ Rm,n be the (image) data, than ug ∈ Rm,n denotes a smoothed version of u.Especially since Matlab is well adapted to matrix operations, a matrix based finite elementapproach is used here. The basic idea is presented in [2].We need to discretize all the terms.The operator div is discretized diagonally at cell corners

div(fi,j) =fi+1/2,j+1/2 − fi−1/2,j−1/2√

2h+fi−1/2,j+1/2 − fi+1/2,j−1/2√

2h,

where h is the height and width of the cells. Since we need to compute div(g(|∇u|)∇u)we discretize ∇u at (i+1/2,j+1/2). Accordingly we have obtained

∇ui+1/2,j+1/2 = [ui+1,i+1 − ui,j√

2h,ui,j+1/2 − ui+1/2,j√

2h]t ,

which leads to following discretization of the whole term:

2h2[div(g(|∇ug|)∇u]i,j = g(|∇ugi+1/2,j+1/2|)[ui+1,j+1 − ui,j]−g(|∇ugi−1/2,j−1/2|)[ui,j − ui−1,j−1] + g(|∇ugi−1/2,j+1/2|)[ui−1,j+1 − ui,j]

− g(|∇ugi+1/2,j−1/2|)[ui,j − ui+1,j−1]

There are ways to discretize div(∇u) with even fewer points but this leads to a less stableimplementation and smoothing the signal (which is the disadvantage of using more points)is part of the algorithm anyway.Furthermore we then want to find a matrix A(|∇ug|) ∈ Rm·n,m·n such that:

2h2[div(g(|∇ug|)∇u](:) = A(|∇ug|) ∗ u(:) ,

where in the second equation the matrices ui,j and div(...)i,j are written as column vectorsas in Matlab notation

u(:)k = uk mod m,dk/me, k ∈ 1, 2, ...m · n\m, 2m, 3m, ...,m · n (1.21)

u(:)k = um,dk/me, k ∈ m, 2m, 3m, ..., n ·m (1.22)

16

Page 20: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

The matrix A should also include the border-condition (1.15). In areas which arenot at the borders of the image u, the value of Ar,s is determined quite easily since ourdiscretization of 2h2[div(g(|∇ug|)∇u]i,j can be written as:

−ui,j · [g(|∇ugi+1/2,j+1/2|) + g(|∇ugi−1/2,j−1/2|) + g(|∇ugi−1/2,j+1/2|) + g(|∇ugi+1/2,j−1/2|)]

+g(|∇ugi+1/2,j+1/2|)ui+1,j+1 + g(|∇ugi−1/2,j−1/2|)ui−1,j−1

+g(|∇ugi−1/2,j+1/2|)ui−1,j+1 + g(|∇ugi+1/2,j−1/2|)ui+1,j−1 .

The border condition is implemented implicitly by treating values with out of boundsindexes as their reflections across the boundary (e.g. ui,n+1 = ui,n−1).

To avoid unnecessary computation of |∇ug|, we define D ∈ Rm+1,n+1 as

Di+1,j+1 = |∇ug|i−1/2,j−1/2

and in regions outside the borders only the gradients parallel to the borders are considered( e.g. Di,n+1 = |∇ug|i−1/2,n+1/2 = |ugi,n−ugi−1,n

h| )

We are now able to define A with a relatively small computational costs.Let A be a m · n×m · n matrix filled with zeros.

for k = 1 to m · ncompute k according to (1.20),(1.21)

if we’re not near the border, define the entries of the k-th row:entry for u(i,j):

A(k, k) = −[g(|∇ugi+1/2,j+1/2|)+g(|∇ugi−1/2,j−1/2|)+g(|∇ugi−1/2,j+1/2|)+g(|∇ugi+1/2,j−1/2|)]

entry for u(i+1,j+1):A(k, k +m+ 1) = g(D(i+ 1, j + 1))

entry for u(i-1,j-1):A(k, k −m− 1) = g(D(i, j))

entry for u(i-1,j+1):A(k, k +m− 1) = g(D(i, j + 1))

entry for u(i+1,j-1)A(k, k −m+ 1) = g(D(i+ 1, j))

In case (i,j) lies on a border of the image, change the definitions above according to ourreflection across the border.

17

Page 21: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

In the next step we need to compute u(t+ ∆t) for some given u(t).An explicit approach would be given by:

u(t+ ∆t) = u(t) + ∆t∂u(t)

∂t,

which in our notation becomes:

u(t+ ∆t)(:) = u(t)(:) + ∆t · A(|∇ug|) ∗ u(t)(:) .

In fact this approach is very simple and even stable for very small ∆t.

The fully implicit system:

u(t+ ∆t)(:) = u(t)(:) + ∆t · A(|∇ug(t+ ∆t|) ∗ u(t+ ∆t)(:)

takes far too long to realize. As proposed in most sources We therefore implement asemi-implicit approach which in principle looks as follows:

u(t+ ∆t)(:) = u(t)(:) + ∆t · A(|∇ug(t|) ∗ u(t+ ∆t)(:)

⇔ (Id−∆t · A(|∇ug(t)|)) ∗ u(t+ ∆t) = u(t)

⇔ u(t+ ∆t) = (Id−∆t · A(|∇ug(t)|))−1 ∗ u(t) . (1.23)

In each iteration we need to invert the matrix I = (Id−∆t ·A(|∇ug(t)|) This is done quiteeasily since (Id−∆t · A(|∇ug(t)|) is diagonally dominant since

−A(k, k) =∑i 6=k

|A(k, i)| , where A(k,k) < 0

=⇒ I(k, k) = 1 + ∆t · |A(k, k)| >∑i 6=k

|A(k, i)| =∑i 6=k

|I(k, i)| .

We can therefore use the CGNR algorithm as it is presented in [14]. This indeed provedto be a fast and stable way to invert I in praxis.Depending on how the image is structured (dimension of the image, what edges shall beenhanced and how is the noise distributed) we now have to chose a flux function g and foreach step a smoothing-kernel for ug.Choosing the functionAs a start we implemented the functions given in [2]. Since in our case this functionsseemed to enhance edges with quite different gradients, we scaled these functions in orderto compare them directly.

g1(s, λ) =5

1 + 4 · (s/λ)2,

g2(s, λ) =5

(1 + (s/(2 · λ))2)2,

18

Page 22: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

g3(s, λ) = e−0.12(s/λ)2 .

These functions gıve very similar results, but function g2 results in the most suitableoutcomes in our case.Choosing and changing the kernelWhy do we have to change the kernel for each time-step?We will take a look at the Gaussian kernel with standard deviation σ. In the beginningthe noise may be very strong and σ is chosen to be large in order to get a small gradient ofug even near noise-peaks. After a few steps, (depending on step-width and flux-functiong) most of the noise is reduced on planes but close to edges noise is still apparent since inug the area of an edge is much bigger than the actual edge area in u. We therefore lessenσ in order to reduce noise even near edges.

1.3.2 What Problems May/Did Occur

• The main problem of the Perona-Malik diffusion is speed. The matrix A we intro-duced above has m2 · n2 elements for an m× n image.Depending on the platform used, Matlab can only handle variables of a certain di-mension, this boundary is exceeded quite easily. We therefore define our Matrix tobe sparse which saves a lot of memory, for every row has a maximum of 5 non-zerovalues. The disadvantage of a sparse matrix in Matlab is that the speed is reducedsignificantly even if the data is prelocated.

• Even though we found a family of functions g(·, λ) which worked quite well for allof our data, the user still has to choose a λ that leads to satisfactory results (e.g. itmay be necessary to change λ if a different kind of workpiece is analyzed). This lackof genericity is not easy to eliminate, judging only by the data the algorithm cannotknow what edges are important to the user.

• Let’s take a look at physics again to understand the next possible problem. In 1Dthere is only one way for material or heat to flow from one plateaus into a deeperlying one, across it’s border. In 2D this is not the case. If there is a region where theedge of the plateau is not strong enough, material may flow from one plateau intothe next even though most of the edges are high enough. Though in Theory quiteapparent we were not able to produce this kind of error in a noticeable way.

• There is another major flaw: Sometimes the workpieces were not scanned at the rightangle. The Bottom is tilted sideways in that case the Perona-Malik diffusion mayresult in two or more plateaus where originally we expected one tilted plane. Thismay result in additional edges and might influence the assessment of the workpiece’squality. See Figure (1.5), (1.6)

• Another problem stems from errors produced by the microscope. Whenever the rimof the cup reaches the image border additional noise is produced as in Figure (1.2).

19

Page 23: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

After the Perona-Malik diffusion is applied, the rim then appears to be flattened(Figure (1.3) and (1.4)).

1.4 Appliance to our Data

Figure 1.2: The plot of the original height data.

Application to sample data showed that the Perona-Malik equation indeed gives us thedesired results when it comes to noise reduction and edge enhancement. On the otherhand, it was a setback to see how long even a few iterations take. Further studies showedthat it takes the majority (around 95%) of the time to define the matrix A from (1.22)and invert (Id− A) in each step.For a 154× 205 image, the definition of A alone takes ≈ 0.3s!.

1.4.1 Application to Workpiece Data

Best results where achieved using up to 40 iterations of the CGNR iterative method in eachstep but only around 8 steps of the Perona-Malik method itself since, even using adaptivestep size control, the image hardly changes after the first iterations.

20

Page 24: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Figure 1.3: Data after 15 iterations

Figure 1.4: Data after 30 iterations.

21

Page 25: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

1.4.2 Examples of the Problems that did Occur

Figure 1.5: Image of the original work-piece. Though the surface is roughthere is no strong edge on the inside.

Figure 1.6: The height data after theP-M algorithm was applied. Thereare now discernible edges inside theworkpiece. Note that we deliberatelychanged the parameters to produce thiserror.

Further tests and application to our workpiece data may be found in Appendix A.

22

Page 26: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Chapter 2

Characterization

So far we only enhanced the information on our workpiece contained in the image butwe have yet to extract it. In this section we will present three algorithms devised tocharacterize certain properties of the cup.

2.1 What information are we looking for?

The main goal is to extract parameters and values representing the incidence of produc-tion errors in the current workpiece. There are lots of different defect classes that mostlyhave totally different causes. It would therefore be good to asses as many defect classesseparately as possible.

2.2 Parameters of the workpiece

In our case we’re looking for the ellipse which fits the outline of our workpiece best, thisalso gives us a value for the first defect class: “ellipticity”.There are many works available on ellipse-detection in images and like [10] every paper,uses a modified Hough transformation approach. This may be very useful if we have noknowledge of the nature of the ellipse, but in our case we have the advantage to be relativelycertain that, after we applied the Perona-Malik algorithm, there are no significant edgesoutside the ellipse. Plus there may be a second ellipse inside the outer rim (as seems to bequite often the case in the images) a Hough Transformation-based approach is then likelyto return the parameters of the wrong ellipse in some cases.We therefore present a new algorithm which resembles the Snakes algorithm [11] insofarthat we position a test ellipse around our suspected workpiece and in each iteration steptry to find a better fitting test ellipse. As far as the author knows this has not yet beendone in this context. As before, we will only look at the problem at hand which is findingan ellipse. Part of the algorithm may well be applied to a wider range of convex structures

23

Page 27: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

though.

Figure 2.1: Sketch of the ellipse and the test ellipse outside of it. (m0,n0) is the center ofthe test ellipse, a and b denote the main axes and α describes how the ellipse is rotatedrelative to the x-axis.

The general outline of the algorithm:1) load image u2) set initial values: (m0,n0),a,b,α(Only restriction to the initial values: The Test ellipsedefined by these parameters has to contain the ellipse we want to find.while(We have only none, one or two points of contact.)

3) Search the Test-ellipse for points of contact.4) Combine points of contacts if they are near to each other(we don’t expect our ellipse to be perfectly regular).if (We have only one point of contact.)

Move the center (m0,n0) accordingly.else if (We have two points of contact which are approximately opposite each other.)

if( These points lie on one of the principal axis of our test-ellipse.)Reduce the other principal axis.

elseRotate the test-ellipse accordingly by changing the angle α.

endelse

24

Page 28: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

In this case we have reached the ellipse to a certain degree.end end

This Algorithm is based on the fact, that two ellipses of which one lies in the other,cannot touch in more than two points. This algorithm proved to be quite stable and fastas long as there are only negligible edges outside the ellipse.A combination with an eliminating particle swarming optimization as is done by the authorsin [12] is neither fast nor did it help to increase the quality of the found parameters. In somecases the swarming method even led away from the wanted parameters. One reason for thissurely is that we search for the outer ellipse and not for the strongest ellipse somewhere inthe image.

2.2.1 Problems and Conditions Placed on the Image

This algorithm proved to be stable and fast as long as some points are ensured:

• There is an ellipse to be found in the image.

• The ellipse is inside the test ellipse defined by the initial values of the algorithm.

• There are no major edges outside the ellipse. This is quite important as, unlikeHough Transformation the algorithm is highly sensitive towards noise outside theellipse.

• The ellipse is represented by enough edges in all directions. If for example only theupper half of the ellipse is discernible the algorithm is likely to fail.

2.3 Assessment of the Rim’s Characteristic

Having found the ellipse which approximates the outline of our workpiece best, we nowwant to evaluate how the edge itself is structured. For this we transform the 2 dimensionaloutline of the workpiece into an one dimensional function p(φ) such that p(φ) is the distanceof the actual edge to the optimal ellipse for φ ∈ [0, 360]

25

Page 29: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Figure 2.2: Transformation of the rim into a function.

To find this function, the algorithms looks for the outermost edge for every φ. If thedistance is less than 30 pixels from found the ellipse, the distance and the associated angleφ is saved into two vectors. If the distance is greater than 30 pixels we may not be surethat what we are looking at is part of the outer rim and the distance and angle values areignored.The desired function p(φ) is then determined using smoothing an interpolation in casethere are no values for some angles φ.There are now at least two possible ways to assess the edge by means of analyzing p:

• Get the average value p = 1360

∫ 360

0p(φ) dφ and calculate the deviation of p:

dev =

∫ 360

0

|p(phi)− p| dφ

.The resulting dev is a value for all production errors of the rim finer than ellipticity.To get a more general value for the quality this is normalized by dividing by thenumber of edge-points found in the image. Otherwise, a workpiece where we wereable to detect the whole rim would always be more likely to get a high ripple-valuethan a workpiece where we could only find half of the rim-points (this could forexample be the case if not the whole workpiece is visible in the image).

• Fourier analysis of p gives information about how the rim is structured exactly. Thismight be the most useful approach in practice since ripples with higher frequenciesmostly have totally different causes compared to ripples with low frequency.

26

Page 30: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

2.3.1 Application to our Measurement Data

Figure 2.3: Results of our ellipse-finding algorithm when applied to the height data plottedin Figure 1.3

Figure 2.4: Plot of the workpiece’s rim belonging to the image above. First plot is the rawdata, second plot is a smoothed version thereof.

27

Page 31: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

2.4 Evaluating the Quality of the Workpiece’s Bottom

Following is a number of production-errors that may occur according to theory. We wrotedown ideas how to extract most of them from the image-data but only implemented analgorithm to evaluate the form quality.Possible production errors are:

• Cracks of various forms and lengths.A way to find cracks could be a Hough transformation of the edge image. Real crackshave an almost infinite gradient and their edge should be easily found using the Sobelalgorithm with very high threshold.

• Stretcher strains (Luder lines).We could not find them in the images containing height data. Photos of the work-piece could be helpful here. (The Keyene microscope also produces photographs ofthe workpiece with the same image dimension and workpiece position. The extractedworkpiece parameters can therefore also be applied to the photos).

• Surface roughness.There is too much noise before, and to little roughness after the Perona-Malik algo-rithm is applied. Statements about the surface roughness will be very hard to make.Just as the Luder Lines, they might be found in the photos of the workpiece.

• General errors in the form of the Bottom.An algorithm is presented in the following paragraph.

• Cracks in the rimAn idea is described in section 2.5.

The form evaluating program should compare the height data of the cup with the shapeof the desired cup and return a values that represents the deviation between these two.Let g(r) be a function which for every 0 ≤ r ≤ rMAX describes the height difference be-tween the center and the points, where r is the distance between the center and the pointin the (X − Y ) plane in our ideal cup and rMAX is the found ellipse radius. This programwill only be run in case the workpiece is almost perfectly circular.One problem that occurs in almost all cases is a tilt of the cup. As a first step the Algo-rithm therefore calculates c1, c2 and c3 of the plane c1 ∗ (i−m0) + c2 ∗ (j − n0) + c3 whichhas minimal square distance to the points of the workpiece’s bottom((m0, n0) is the centerof the workpiece and i, j is the position in the image data).Using this plane, we calculated the constant d such that g(r) + d fits the cup best, com-pensating the tilt.Comparison between g(r)+d the height data indeed gives us a value representing the formquality of the bottom and to a degree the quality of the rim’s curvature.

28

Page 32: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

2.4.1 Application

In these two images we replaced part of the actual height-data with the found ideal data.The strong dependency on the correct choice of g(r) becomes apparent in these two images.

Figure 2.5: Here half of the bottom is replaced with the ideal form, using g(r) =− 100√

rMAX−10−r

Figure 2.6: In this image the given g(r) equals zero

29

Page 33: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

2.5 How to Find Cracks in the Rim

Besides ripples on the edge, we may also encounter cracks in the edge. Cracks cannot easilybe found using the edge-function p so we came up with something different:The general Idea is to use a Hough transformation detecting lines in the area near theoptimal ellipse in radius and φ coordinates such that a line, whose direction is orthogonalto the ellipse, has slope zero. A crack may then be characterized as a high value in theaccumulator with slope near zero. This should bring two advantages:First of all, the restriction of the area we need to transform and the fact that the accu-mulator can be reduced to a few values for the slopes of our lines should shorten the timemany times over.Secondly, we do not have to worry about slope-values near ∞ or −∞ which would be thecase without our transformation into these polar coordinates.this function is not yet fully implemented. Further Test in appendix A.

.

30

Page 34: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Appendix A

Further Tests

A.1 Test1

Figure A.1: Test 1: Original height Data

31

Page 35: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Figure A.2: Test 1: Data after the Perona-Malik diffusion

Figure A.3: Test 1: Found ellipse

32

Page 36: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Figure A.4: Test 1: Plot of the rim

Deviation-value of the rim: 47

Figure A.5: Test 1: Approximation of the inner region

Deviation from the optimal shape: 13.5

33

Page 37: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

A.2 Test2

Figure A.6: Test 2: Original height Data

Figure A.7: Test 2: Height data after the Perona-Malik diffusion

34

Page 38: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Figure A.8: Test 2: Found ellipse

Figure A.9: Test 2: Plot of the rim

Deviation-value of the rim: 57

35

Page 39: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Figure A.10: Test 2: Approximation of the inner region

Deviation from the optimal shape: 2.3

36

Page 40: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Appendix B

Source Code

B.1 Source Code of the Perona-Malik Diffusion

function [ u0 ] = PeronaMalik(u0,maxiter,s,maxinv,gaussw)

%Input parameters:

%u0 the image,

%maxiter =maximum number of iterations

%s =parameter for flow function g is scaled.(higher s -> more smoothing

%maximum =iterations of the CGNR-Algorithm to invert the matrix

%gaussw = parameter to control the gaussian filter for ug

[m,n]=size(u0);

dist = 1;

%kernF is the gaussian kernel which changes with time (sigma decreases)

kernF = fspecial(’gaussian’,[m,n],1);

%We postulate that all images have the width of 1. h is the width of one

%cell in the image

h=1/n;

%D will contain the absolute value of the gradient of ug

D = zeros(m+1,n+1);

%ug later contains the smoothed image data

ug = zeros(m,n);

ug =real(ifftshift(ifft2(fft2(u0).*fft2(kernF))));

%This is the main loop, during which u_n+1 is computed

for iter=1:maxiter

%The gaussian kernel is changed depending on what loop ieration we’re

%in

kernF = fspecial(’gaussian’,[m,n],n*gaussw/(100*(3+iter/30)^(1/10)));

%We define D for this iteration D(k,l) = sqrt(sqrt(2)*h)* |grad(k-1/2,l-1/2)|

%= sqrt((ug(k,l)- ug(k-1,l-1))^2 + (ug(k-1,l)-ug(k,l-1))^2)

37

Page 41: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

%The inner region of D:

for k=2:m

for l=2:n

D(k,l) = sqrt((ug(k,l)- ug(k-1,l-1))^2 + (ug(k-1,l)-ug(k,l-1))^2);

end

end

%Borders of D:

for l=2:n

D(1,l) = (2)^(1/2)*abs(ug(1,l)-ug(1,l-1));

D(m+1,l) = (2)^(1/2)*abs(ug(m,l)-ug(m,l-1));

end

for k=2:m

D(k,1) = (2)^(1/2)*abs(ug(k,1)-ug(k-1,1));

D(k,n+1) = (2)^(1/2)*abs(ug(k,n)-ug(k-1,n));

end

%Scaling D:

D= 1/(sqrt(2)*h)*D;

%A is a matrix such that div(g(|nabla ug|)*nabla u) =

%A*u(:)

%We define (I-stepwidth*A);

%We need 2*3*(m+n) entries for the borders and 5*(m-2)*(n-2) entries for

%non-bordersections

l=(n-2)*(m-2)*5 + 2*3*(n+m-4); %number of non-zero entries in I and A

sw=zeros(1,l); %values

i=zeros(1,l); %position i

j=zeros(1,l); %position j

pe=1;

if dist==1

stepw = (70)/(h^2);

else

stepw = (9800)^2/((dist*h)^2);

end

for pz=1:m*n

%pz is the row position in A

%pi and pj are the positions in u0

pi= mod(pz,m);

if(pi==0)

pi=m;

end

pj= ceil(pz/m);

if(pi>1&&pj>1&&pi<m&&pj<n)

%Entries on the diagonal

sw(pe) =1+stepw*(g2(D(pi+1,pj+1),s)+g2(D(pi,pj),s)+...

g2(D(pi,pj+1),s)+g2(D(pi+1,pj),s));

i(pe) = pz;

j(pe)= pz;

38

Page 42: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

%Entries for u(i+1,j+1):

sw(pe+1) =-stepw*g2(D(pi+1,pj+1),s);

i(pe+1) =pz;

j(pe+1) = pz+1+m;

%Entries for u(i-1,j-1)

sw(pe+2) = -stepw*g2(D(pi,pj),s);

i(pe+2) = pz;

j(pe+2) = pz-m-1;

%Entries for u(i-1,j+1)

sw(pe+3) = -stepw*g2(D(pi,pj+1),s);

i(pe+3) = pz;

j(pe+3) = pz+m-1;

%Entries for u(i+1,j-1)

sw(pe+4) = -stepw*g2(D(pi+1,pj),s);

i(pe+4) = pz;

j(pe+4) = pz-m+1;

pe = pe+5;

elseif(pi==1&&pj~=1&&pj~=n)

%Entries on the diagonal:

sw(pe) = 1+stepw*(g2(D(pi+1,pj+1),s)+g2(D(pi+1,pj),s));

i(pe) = pz;

j(pe) = pz;

%Entries for u(i+1,j+1):

sw(pe+1) =-stepw*g2(D(pi+1,pj+1),s);

i(pe+1) = pz;

j(pe+1) = pz+m+1;

%Entries for u(i+1,j-1)

sw(pe+2) = -stepw*g2(D(pi+1,pj),s);

i(pe+2) = pz;

j(pe+2) = pz-m+1;

pe=pe+3;

elseif(pj==1&&pi~=1&&pi~=m)

%Entries on the diagonal:

sw(pe) =1+stepw*(g2(D(pi+1,pj+1),s)+g2(D(pi,pj+1),s));

i(pe)= pz;

j(pe)= pz;

%Entries for u(i+1,j+1):

sw(pe+1) = -stepw*g2(D(pi+1,pj+1),s);

i(pe+1) = pz;

j(pe+1) = pz+m+1;

%Entries for u(i-1,j+1)

sw(pe+2) = -stepw*g2(D(pi,pj+1),s);

i(pe+2) = pz;

j(pe+2) = pz+m-1;

pe = pe+3;

elseif(pi==m&&pj~=1&&pj~=n)

%Entries on the diagonal:

sw(pe) = 1+stepw*(g2(D(pi,pj),s)+g2(D(pi,pj+1),s));

39

Page 43: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

i(pe) = pz;

j(pe) = pz;

%Entries for u(i-1,j-1)

sw(pe+1)= -stepw*g2(D(pi,pj),s);

i(pe+1) = pz;

j(pe+1) = pz-m-1;

%Entries for u(i-1,j+1)

sw(pe+2) = -stepw*g2(D(pi,pj+1),s);

i(pe+2) = pz;

j(pe+2) = pz+m-1;

pe = pe+3;

elseif(pj==n&&pi~=1&&pi~=m)

%Entries on the diagonal:

sw(pe) = 1+stepw*(g2(D(pi,pj),s)+g2(D(pi+1,pj),s));

i(pe) = pz;

j(pe) = pz;

%Entries for u(i-1,j-1)

sw(pe+1)=-stepw*g2(D(pi,pj),s);

i(pe+1)=pz;

j(pe+1)=pz-m-1;

%Entries for u(i+1,j-1)

sw(pe+2)=-stepw*g2(D(pi+1,pj),s);

i(pe+2) = pz;

j(pe+2) = pz-m+1;

pe = pe+3;

end

end

%Defining I

I = sparse(i,j,sw,m*n,m*n,l);

%In order to compute u_n+1 we have to invert (Id-A).

%We use the Conjugate Gradient on Normal Equations (CGNR),

%starting value is u_n (since u_n+1 should be near u_n).

%I is the matrix we need to invert. Step width is cntrolled by

%dist =||u_n - n_(n-1)||.

x=u0(:);

r = I’*(I*x-u0(:));

ra = r;

beta=0;

d=0;

a=0;

rel = norm(x);

for k=0:maxinv

if norm(r)<(iter)^(1/2)*10^8*rel && k>5

disp(k)

break;

else

40

Page 44: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

if k>0

r2 = (r’*r);

beta = r2/(ra’*ra);

d=-r+beta*d;

Id = I’*(I*d);

a=r2/(Id’*d);

x= x +a*d;

ra=r;

r = r + a*Id;

else

d=-r;

r2 = (r’*r);

Id = I’*(I*d);

a=r2/(Id’*d);

x= x +a*d;

ra=r;

r = r + a*Id;

end

end

end

%Do the step...

dist = norm(u0(:)-x);

u0(:) = x;

%Get new smoothed image.

ug =real(ifftshift(ifft2(fft2(u0).*fft2(kernF))));

%Stop if u barely changed.

if(dist<60)

break;

end

end

figure(2)

surf(u0);

title([’height data after’ num2str(iter) ’ iterations’]);

end

The flux function:

function [ y ] = g2( s,l)

%y=5/(1+4*(s/l)^(2));

y=5/(1+1/4*(s/l)^(2))^2;

%y=exp(-0.12*(s/l)^2);

end

B.2 Source Code of the Parameter Search

function[m0,n0,a,b,dreh]= paraSearch(u0)

41

Page 45: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

%The parameter u0 should contain a noise-free image u0 containing an

%ellipse.

%It then computes the center: (m0,n0), the main axes a and b and the

%rotaion: dreh of this ellipse.

%get the edges that are locally maximal and greater than the threshhold

ue = edge(u0,’sobel’,2.9);

[m,n] = size(ue);

ue=double(ue);

kern = fspecial(’gaussian’,[9,9],1);

%the smoothing helps to increase the stability.

uef= [[ue(4:-1:1,4:-1:1);ue(1:m,1:4);ue(m:-1:m-4,4:-1:1)],...

[ue(4:-1:1,1:n);ue;ue(m:-1:m-4,1:n)],...

[ue(4:-1:1,n:-1:n-4);ue(1:m,n:-1:n-4);ue(m:-1:m-4,n:-1:n-4)]];

ue=conv2(uef,kern,’valid’);

[m,n] = size(ue);

%The ellipse is: (x-xo)^2/a^2 +(y-yo)^2/b^2 = r^2 rotated by phi.

%initial values:

m0 =m/2;

n0=n/2;

a=m/2+30;

b=m/2+35;

dreh=0; %in radiant

%remeber the last center-points and rotations to avoid "shaking"

versch = false;

peakalt = 0;

peakalt2=0;

peakalt3=0;

peakalt4=0;

drehold =0;

drehold2=0;

gedreht=false;

for iter=1:120

%Scan where our test-ellipse touches edges.

beruhr=zeros(1,720);

%If desired color the image at this point.

ub = ones(m,n,3);

ub(:,:,1) =ub(:,:,1)- 2*ue;

ub(:,:,2) =ub(:,:,2)- 2*ue;

ub(:,:,3)=ub(:,:,3)-2*ue;

Dreh = [cos(dreh),-sin(dreh);sin(dreh),cos(dreh)];

for phi=1:720

rad=pi*phi/(360);

y=a*cos(rad);

x=b*sin(rad);

p=Dreh*[x;y];

if(round(m0-p(2))>0&&round(m0-p(2))<=m&&round(n0+p(1))>0&&round(n0+p(1))<=n&&...

ue(round(m0-p(2)),round(n0+p(1)))>0)

42

Page 46: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

beruhr(phi)=ue(round(m0-p(2)),round(n0+p(1)));

end

ub(min(m,max(1,round(m0-p(2)))),min(n,max(1,round(n0+p(1)))),2) =0;

ub(min(m,max(1,round(m0-p(2)))),min(n,max(1,round(n0+p(1)))),1) =0;

ub(min(m,max(1,round(m0-p(2)))),min(n,max(1,round(n0+p(1)))),3) =0;

end

kern= fspecial(’gaussian’,[1,720],30);

%Stop if the ellipse already lies on a certain amout of edgepoints.

if sum(beruhr)>pi*sqrt(2*(a^2+b^2))/8

break;

end

bg = conv([beruhr(359:-1:1),beruhr,beruhr(720:-1:361)],kern,’valid’);

[pks,locs]=findpeaks([0,bg,0],’sortstr’,’descend’,...

’minpeakdistance’,5,’minpeakheight’,0.02);

%Find peaks that are too near to each other.

l=numel(locs);

for i = 1:l

for j=i+1:l

if j>l

break;

end

if abs(locs(i)-locs(j))>430

locs = [locs(1:i-1),mod((locs(i)+locs(j)+720)/2,720),...

locs(i+1:j-1),locs(j+1:l)];

l=l-1;

if j==l

break;

end

elseif abs(locs(i)-locs(j))<290

locs = [locs(1:i-1),(locs(i)+locs(j))/2,locs(i+1:j-1),locs(j+1:l)];

l=l-1;

if j==l

break;

end

end

end

end

if numel(pks>0)

locs = locs-ones(1,numel(locs));

end

%Depending on where and how the test ellipse touches the rim of the cup

%we change the parameters of the test-ellipse.

if numel(locs) ==1

%Compare poisitions between iterations to avoid repetitions.

if versch>=1&&abs(abs(locs(1)-peakalt)-360) <30

locs = [locs,peakalt];

versch=0;

43

Page 47: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

elseif versch>=2&&abs(abs(locs(1)-peakalt2)-360) <60

locs = [locs,peakalt2];

versch=0;

elseif versch>=3&&abs(abs(locs(1)-peakalt3)-360) <60

locs = [locs,peakalt3];

versch=0;

elseif versch>=4&&abs(abs(locs(1)-peakalt4)-360) <60

locs = [locs,peakalt4];

versch=0;

end

end

if(numel(locs)==2)

peakalt = pks(1);

%We have two maximums.

if abs(abs(locs(1)-locs(2))-360)<70

%They lie opposite each other.

%We calculate the main axis:

loc=mod((locs(1)+locs(2))/2 +180,360);

if mod(loc,360) <40 || abs(mod(loc,360)-360)<40

%Rotation ok, lessen b

b=b-1;

versch=0;

gedreht=0;

elseif abs(loc-180)<40 || abs(loc-540)<40

%Rotation ok, lessen a

a=a-1;

versch=0;

gedreht=0;

else

%Wrong rotation, change dreh.

%To avoid repetion, we compare old and new rotations in

%case we turned in the last iteration as well.

if b>a

dreh = dreh +(pi*(180-loc)/360);

if abs(drehold2-dreh)<0.1 &&gedreht>1

dreh = (dreh+drehold)/2;

end

drehold2=drehold;

drehold=dreh;

elseif a>b

dreh = dreh - (pi*loc/360);

if abs(drehold2-dreh)<0.1&&gedreht>1

dreh = (dreh+drehold)/2;

end

drehold2=drehold;

drehold=dreh;

else

dreh = dreh+ (pi*(loc)/360);

if abs(drehold2-dreh)<0.1&&gedreht>1

44

Page 48: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

disp([dreh,drehold,drehold2])

dreh = (dreh+drehold)/2;

end

drehold2=drehold;

drehold=dreh;

end

gedreht=gedreht+1;

versch=0;

end

else

%The points of contact do not lie opposite each other,

%move according to the combined maximum.

versch=versch+1;

gedreht=0;

if(abs(locs(1)-locs(2))<360)

kombmax = (locs(1)+locs(2))/2;

peakalt4=peakalt3;

peakalt3=peakalt2;

peakalt2=peakalt;

peakalt = kombmax;

else

kombmax = (locs(1)+locs(2)+720)/2;

end

v1=cos(pi*kombmax/360); %m-Wert

v2=sin(pi*kombmax/360); %n-Wert

v=Dreh’*[v1;v2];

m0 =m0 - v(1);

n0 =n0 + v(2);

end

elseif(numel(locs)==1)

%Move away fromt he maximum.

v1=cos(pi*locs(1)/360); %m-value

v2=sin(pi*locs(1)/360); %n-value

v=Dreh’*[v1;v2];

m0 =m0 - v(1);

n0 =n0 + v(2);

peakalt4=peakalt3;

peakalt3=peakalt2;

peakalt2=peakalt;

peakalt = locs(1);

versch = versch+1;

gedreht=0;

elseif numel(locs)==0

%No peaks, we therefore lessen both a and b.

a=a-1;

b=b-1;

gedreht=0;

versch=0;

else

%Too many points of contact.

45

Page 49: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

break;

end

if mod(iter,4)==0

figure(3)

imagesc(ub);

title(’Current edge image and the found ellipse’);

end

end

a=round(a);

b=round(b);

figure(3)

imagesc(ub);

colormap gray;

title(’Edge image and the found ellipse’);

end

B.3 Source Code of the Edge Characterization

function [ wert1 ] = rimcharact(u0,m0,n0,a,b,dreh )

%This function shall characterize the workpiece’s rim.

%This includes first a value for the overall ripples on the edge

%and may also contain a frequancy analysis of the edge.

[m,n]=size(u0);

r = ceil(max(a,b)); %The maximum radius. We assume the workpiece to be round

%Since we now the position and size of our workpiece, we may look at a

%smaller region.

uk=u0(max(1,round(m0-r)):min(m,round(m0+r)),max(1,round(n0-r)):min(n,round(n0+r)));

m0 = r-min(0,m0-r);

n0 = r-min(0,n0-r);

[m,n]=size(uk);

%The ripples of the edge are characterized by p(phi)=distance between outer

%rim and found ellipse at angle phi.

%We’re again working with the edge-image

uke= edge(uk,’sobel’,4);

%transformation-matrix

Dreh = [cos(dreh),-sin(dreh);sin(dreh),cos(dreh)];

diff=35;

erst=true;

for phi=1:719

%get position in image for phi

rad=pi*phi/(360);

y=cos(rad);

x=sin(rad);

46

Page 50: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

radius=sqrt((a*y)^2 + (b*x)^2);

p=Dreh*[x;y];

%find the distance between rim and ellipse

for k=radius+3:-1:radius-35

if 0<round(m0-k*p(2))&&m>=round(m0-k*p(2))&&...

0<round(n0+k*p(1))&&n>=round(n0+k*p(1))

if uke(round(m0-k*p(2)),round(n0+k*p(1))) >0

if ~erst

phiwerte = [phiwerte,phi];

radwerte = [radwerte,10*(radius-k)];

uke(round(m0-k*p(2)),round(n0+k*p(1)))=...

uke(round(m0-k*p(2)),round(n0+k*p(1)))+30;

break;

else

phiwerte = phi;

radwerte = 10*(radius-k);

erst=false;

end

end

end

end

end

if numel(phiwerte)<2

disp(’keinen Rand gefunden!’)

return;

end

[l1,l2]=size(phiwerte);

%We need a value for phi=720 for later computations.

phiwerte = [phiwerte,720];

radwerte=[radwerte,radwerte(1,l2)+(720-phiwerte(1,l2))*...

(radwerte(1,1)-radwerte(1,l2))/(phiwerte(1,1)+720-phiwerte(1,l2))];

%So far phiwerte and radwerte only contain values in case we found an

%edge. This may not be the case for all phi. This is a problem in

%ferquency analysis and plotting...

%The function plottable deals with this.

[phiwerte2,radwerte2]= plottable(phiwerte,radwerte);

%Smooth the signal.

kern= fspecial(’gaussian’,[1,50],10);

%convolution with periodic continuation of the signal

radwg = conv([radwerte2(696:720),radwerte2,radwerte2(1:24)],kern,’valid’);

%Show "the edge"

figure(4)

subplot(2,1,1);

plot(phiwerte,radwerte);

47

Page 51: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

xlabel(’2*phi’);

ylabel(’10*dist’);

% set(gca,’FontSize’,24);

subplot(2,1,2);

plot(phiwerte2,radwg);

%title(’plot of the found edge points and a smoothed and optimized version’);

xlabel(’2*phi’);

ylabel(’10*dist’);

%set(gca,’FontSize’,24);

%Get the value for the overall rippleness. this is just a way to receive a simple value.

%in later implementations this schould probably be changed to frequency analysis

wert1=0;

p= polyfit(phiwerte2,radwerte2,2);

pw=polyval(p,phiwerte2);

for k=1:720

wert1=wert1 +abs(radwerte2(k)-pw(k));

end

wert1=wert1/n;

end

B.4 Smoothing the Edge Data

function [ phiwerte2, radwerte2 ] = plottable( phiwerte, radwerte )

% We want to achieve several things:

%a value for every values of phi

%a certain degree of smoothnes in the data

%optional: points with no near neightbours shall not influence our overall picture

%too much.

[m,length]=size(phiwerte);

radwertesm = zeros(1,length);

if length>1

radwertesm(1)=radwerte(1);

radwertesm(length)=radwerte(length);

end

%partly ignore values that are "alone" those values may otherwise give

%falsify our characterization

%

for k = 3:length-2

radwerte(k) = radwerte(k)*sqrt(6)/sqrt(phiwerte(k+1)+...

phiwerte(k+2)-phiwerte(k-1)-phiwerte(k-2));

end

%

%smooth the values

for k=2:length-1

if abs(phiwerte(k-1)-phiwerte(k))<=4&&abs(phiwerte(k+1)-phiwerte(k))<=4

radwertesm(k) = 2/3*radwerte(k)+1/6*(radwerte(k-1)+1/6*radwerte(k+1));

48

Page 52: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

elseif abs(phiwerte(k-1)-phiwerte(k))<=4

radwertesm(k)=3/4*radwerte(k)+1/4*radwerte(k-1);

elseif abs(phiwerte(k+1)-phiwerte(k))<=4

radwertesm(k) = 3/4*radwerte(k)+1/4*radwerte(k+1);

else

radwertesm(k)=radwerte(k);

end

end

%We interpolate the values

phiwerte2 = 1:720;

radwerte2 = zeros(1,720);

%position inside our phi-vector

pos = 2;

%Last-position-value;

lpv=0;

%Last position

lp =0;

for i = 1:720

if i<phiwerte(pos)

radwerte2(i) = lpv+(radwertesm(pos)-lpv)*(i-lp)/(phiwerte(pos)-lp);

elseif i== phiwerte(pos);

radwerte2(i)=radwertesm(pos);

lpv = radwertesm(pos);

lp = phiwerte(pos);

pos=pos+1;

end

end

end

B.5 Source Code of the Form Assessment

function [ dev ] = ingeo(u0,m0,n0,a,b,dreh )

%We’re trying to get a value representing the geometric quality of the cup.

[m,n]=size(u0);

%step 0: get the tilt out of the cup by finding the approximating plane:

%aa(i-mo)+ba(j-n0)+ca = u(i-mo,j-no)

a2 = max(a,b);

b2 = min(a,b);

e = sqrt(a2^2-b2^2);

f1= [m0 - e*sin(dreh);n0+e*cos(dreh)];

f2= [m0 + e*sin(dreh);n0-e*cos(dreh)];

pos=1;

A=zeros(ceil(pi*a*b)/9,3);

f=zeros(ceil(pi*a*b)/9,1);

for i=1:3:m

for j=1:3:n

if(norm([i-f1(1),j-f1(2)])+norm([i-f2(1),j-f2(2)])<2*(a2-20))

A(pos,:)=[i-m0,j-n0,1];

49

Page 53: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

%smoothing of the image to save time

f(pos,1)=1/5*(u0(i,j)+u0(i+1,j+1)+u0(i-1,j-1)+u0(i+1,j-1)+u0(i-1,j+1));

pos=pos+1;

end

end

end

[Q,R]=qr(A);

f=Q’*f;

ca = f(3)/R(3,3);

ba = (f(2)-R(2,3)*ca)/R(2,2);

aa = (f(1)-R(1,3)*ca-R(1,2)*ba)/R(1,1);

rcirc= round( (a+b)/2)-35;

radi=round((a+b)/2);

%To reduce computation-time we assume the workpiece to be round.

%elliptical workpieces would not need to be characterized at this point.

dist=0;

nvalues = 0;

for i=round(min(1,m0-rcirc)):round(max(m0+rcirc,m))

for j=round(n0-sqrt(rcirc^2-(i-m0)^2)):round(n0+sqrt(rcirc^2-(i-m0)^2))

dist = dist +(u0(i,j)-aa*(i-m0)-ba*(j-n0)-geofunc(norm([i-m0,j-n0]),radi));

nvalues = nvalues+1;

end

end

d=dist/(nvalues);

dev=0;

for i=round(min(1,m0-rcirc)):round(max(m0+rcirc,m))

for j=round(n0-sqrt(rcirc^2-(i-m0)^2)):round(n0+sqrt(rcirc^2-(i-m0)^2))-1

temp= (u0(i,j)-aa*(i-m0)-ba*(j-n0)-geofunc(norm([i-m0,j-n0]),radi)-d);

dev = dev+abs(temp);

u0(i,j)=aa*(i-m0)+ba*(j-n0)+geofunc(norm([i-m0,j-n0]),radi)+d;

end

end

figure(5)

surf(u0)

title(’height data with optimal shape’);

dev= dev/(a*b);

end

50

Page 54: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Bibliography

[1] Kristian Bredies and Dirk Lorenz. Mathematische Bildverarbeitung: Einfuhrung in Grundlagen undmoderne Theorie. Vieweg+Teubner, 2011.

[2] L.Keeling and Rudolf Stollberg. Nonlinear anisotropic diffusion filterung for multiscale edge enhance-ment. Inverse Problems, 18:175-190, 2002

[3] Pietro Perona and Jitendra Malik. Sclae-space and edge detection using anisotropic diffusion. IEEETrans. Pattern Anal. Machine Intell., 12:629-639, 1990.

[4] Wieland Richter. Partielle Differentialgleichungen, Einfuhrung in Theorie und Praxis mit FortranProgrammen. Spektrum Akademischer Verlag GmbH Heidelberg Berlin Oxford 1995.

[5] Hans Wilhelm Alt. Lineare Funktionalanalysis, 5., uberarbeitete Auflage. Springer-Verlag Berlin Hei-delberg 2006.

[6] Dirk Werner. Funktionalanalysis. Springer-Verlag, 6., korrigierte Auflage. Springer-Verlag Berlin Hei-delberg 2007.

[7] Francine Catte, Pierre-Louis Lions, Jean Michel Morel and Tomeu Coll. Image Selective Smoothingand Edge Detection by Nonlinear Diffusion. SIAM Journal on Numerical Analysis, Vol 29,No. 1.(Feb.,1992),pp. 182-193.

[8] Lawrence C. Evans, Partial Differential Equations. Graduate Studies in Mathematics Volume 19.American Mathematical Society Providence, Rhode Island 1998

[9] Tychonoff A.: Ein Fixpunktsatz. Math. Ann. 111, 767-776 (1935)

[10] Yonghong Xie and Qiang Ji. A New Efficient Ellipse Detection Method. In International Conferenceon Pattern Recognition 2002

[11] Michael Kass, Andrew Witkin and Demetri Terzopoulos. Snakes: Active Contour Models. Interna-tional Journal of Computer Vision 1998

[12] Yanhui Guo, H.D. Cheng1, Wei Zhao1 and Yingtao Zhang1. A Novel Hough Transform Based onEliminating Particle Swarm Optimization and its Applications. of the 11th Joint Conference on In-formation Sciences (2008)

[13] http://www.keyence.de/

[14] Robert Plato. Numerische Mathematik kompakt. 4. Auflage. Vieweg+Teubner Wiesbaden 2010.

[15] Otto Forster. Analysis 2 Differentialgleichungen im Rn. Vieweg + Teubner 2008

51

Page 55: Bachelor Thesis - uni-bremen.deto make a de nite statement about the quality of the micro part. The rst subject of this thesis is the application of the Perona-Malik di usion to this

Declaration

I guarantee that I personally wrote this thesis and used only the aforementioned resources.The thesis has not been in any form published or submitted to another examination office.

Bremen, July, 28, 2011

John Wilfried Schlasche

52