# gray morphology

AI and Robotics

Nov 6, 2013 (4 years and 8 months ago)

99 views

Gray
-
Scale

Morphological Filtering

Generalization from binary to gray level

Use f(x,y) and b(x,y) to denote an image and a
structuring element

Gray
-
scale dilation of
f

by
b

(f
⊕b)(s,t)=max{f(s
-
x,t
-
y)+b(x,y)|(s
-
x), (t
-
y)

D
f

and (x,y)

D
b
}

D
f

and D
b

are the domains of f and b respectively

(f
⊕b) chooses the maximum value of (f+ ) in the interval defined by ,
where is structuring element after rotation by 180 degree ( )

Similar to the definition of convolution with

The max operation replacing the summation and

b(x,y) functions as the mask in convolution

It needs to be rotated by 180 degree first

b
ˆ
b
ˆ
b
ˆ
)
,
(
ˆ
y
x
b
b

Gray
-
Scale Dilation

Illustrated in 1D

(f
⊕b)(s)=max{f(s
-
x)+b(x)|(s
-
x)

D
f

and x

D
b
}

f(x)

with slope 1

x

x

A

a

b
(x)

s

{f(s
1
-
x)+b(x)| )|(s
-
x)

D
f

and x

[
-
a/2,a/2]
}

A

s
1

max{f(s
1
-
x)+b(x)| )|(s
-
x)

D
f

and x

[
-
a/
2
,a/
2
]
}

=f(s
1
+a/
2
)+b(
-
a/
2
)= f(s
1
+a/
2
)+A=f(s
1
)+a/
2
+A

s

A

f

b

A+a/2

Flat Gray Scale Dilation

In practice, gray
-
scale dilation is performed
using
flat

structuring element

b(x,y)=0 if (x,y)

D
b
; otherwise, b(x,y) is not defined

In this case, D
b

needs to be specified as a binary
matrix with 1s being its domain

(f
⊕b)(x,y)=max{f(x
-
x’,y
-
y’),
(x’,y’)

D
b
}

It is the same as the “max” filter in order statistic
filtering with arbitrarily shaped domain

D
b

can be obtained using strel function as in binary
dilation case

Flat Gray
-
Scale Dilation

(f
⊕b)(s)=max{f(s
-
x)|

x

D
b
}

f(x)

with slope 1

x

x

A

a

D
b

s

f

b

1

Effects of Gray
-
Scale Dilation

Depending on the structuring element

If all the values are non
-
negative
(including flat gray scale dilation), the
resulting image tends to be brighter

Dark details are either reduced or
eliminated

Wrinkle removal

Gray
-
Scale Erosion

Gray
-
scale erosion of
f

by
b

(f
⊖b)(s,t)=
min
{f(s
+
x,t
+
y)
-
b(x,y)|(s
+
x), (t
+
y)

D
f

and (x,y)

D
b
}

D
f

and D
b

are the domains of
f

and
b

respectively

(f
⊖b) chooses the minimum value of (f
-
b) in the domain defined
by the structuring element

Gray
-
Scale Erosion

(f
⊖b)(s)=min{f(s+x)
-
b(x)|(s+x)

D
f

and x

D
b
}

f(x)

with slope
1

x

x

A

a

b
(x)

s

{f(s
1
+x)
-
b(x)| )|(s+x)

D
f

and x

[
-
a/2,a/2]
}

A

s
1

min{f(s
1
+x)
-
b(x)| )|(s+x)

D
f

and x

[
-
a/2,a/2]
}

=f(s
1
-
a/2)
-
b(
-
a/2)= f(s
1
-
a/2)
-
A= f(s
1
)
-
a/2
-
A

s

A+a/
2

f

b

Flat Gray Scale Erosion

In practice, gray
-
scale erosion is performed
using
flat

structuring element

b(x,y)=0 if (x,y)

D
b
; otherwise, b(x,y) is not defined

In this case, D
b

needs to be specified as a binary
matrix with 1s being its domain

(f
⊖b)(x,y)=min{f(x+x’,y+y’),
(x’,y’)

D
b
}

It is the same as the “min” filter in order statistic
filtering with arbitrarily shaped domain

D
b

can be obtained using strel function as in binary
case

Effects of Gray
-
Scale Erosion

Depending on the structuring element

If all the values are non
-
negative
(including flat gray scale dilation), the
resulting image tends to be darker

Bright details are either reduced or
eliminated

Examples

Reduced

Eliminated

Reduced

Eliminated

Dual Operations

Gray
-
scale dilation and erosion are duals
with respect to function complementation
and reflection

It means dilation of a bright object is equal to
erosion of its dark background

)
,
(
ˆ

and

)
,
(

where
)
,
(
)

(
)
,
)(
ˆ
(

y
x
b
b
y
x
f
f
t
s
b
f
t
s
b
f
c
c
c

Gray
-
Scale Opening and Closing

The definitions of gray
-
scale opening and
closing are similar to that of binary case

Both are defined in terms of dilation and erosion

Opening (erosion followed by dilation)

A

b=(A

b)

b

Closing (dilation followed by erosion)

A
•b=(A

b)

b

Again, opening and closing are dual to each
other with respect to complementation and
reflection

)
ˆ
(
or

)
ˆ
(
b
f
b
f
b
f
b
f
c
c

Geometric Interpretation

Properties of Gray
-
Scale

Opening and Closing

Opening

1.
(
f

b

)

f

2.
If
f
1

f
2
, then (
f

1

b
)

(
f

2

b

)

3.
(
f

b

)

b

=
f

b

Closing

1.
f

(
f

b

)

2.
If
f
1

f
2
, then (
f

1

b
)

(
f

2

b

)

3.
(
f

b

b
) =
f

b

The notation e

r
is used to indicate that the domain
of e is a subset of r and e(x,y)

r(x,y)

The above properties can be justified using the the
geometric interpretation of opening and closing shown
previously

Example

9.31
(a) may
be not correct

Applications of Gray
-
Scale
Morphology

Morphological smoothing

Opening (reduce bright details) followed by closing (reduce dark details)

Alternating sequential filtering

Repeat opening followed by closing with structuring elements of increasing
sizes

A

b
5

A

b
5
•b
5

A
•b
2

b
2
•b
3

b
3
•b
4

b
4
•b
5

b
5

Applications of Gray
-
Scale
Morphology

Effects of dilation (brighter) and erosion (darker) are
manifested on edges of an image

g = (f
⊕b)
-

(f⊖b) can be used to bring out edges of
an image

Applications of Gray
-
Scale
Morphology

Top
-
hat transform

Defined as h = f

(f

b)

Useful for enhancing details in the presence