Introduction to Morphological Operators 18-May-151

Preview:

Citation preview

Introduction to Introduction to Morphological Morphological

OperatorsOperators

Apr 18, 2023 1

About this lecture

• In this lecture we introduce INFORMALLY the most important operations based on morphology, just to give you the intuitive feeling.

• In next lectures we will introduce more formalism and more examples.

04/18/23 2

EROSIONEROSION

04/18/23 3

What We Do Today. 2nd Part

• Introduction to Morphological Operators

– Used generally on binary images, e.g., background subtraction results!

– Used on gray value images, if viewed as a stack to binary images.

• Good for, e.g.,– Noise removal in background

– Removal of holes in foreground / background

• Check: www.cee.hw.ac.uk/hipr

A first Example: Erosion• Erosion is an important morphological

operation

• Applied Structuring Element:

Apr 18, 2023 5

Example for Erosion

Apr 18, 2023 6

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0Output Image

111

Example for Erosion

Apr 18, 2023 7

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0Output Image

111

Example for Erosion

Apr 18, 2023 8

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0Output Image

111

Example for Erosion

Apr 18, 2023 9

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0Output Image

111

Example for Erosion

Apr 18, 2023 10

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 1Output Image

111

Example for Erosion

Apr 18, 2023 11

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 1 0Output Image

111

Example for Erosion

Apr 18, 2023 12

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 1 0 0Output Image

111

Example for Erosion

Apr 18, 2023 13

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 1 0 0 0Output Image

111

Introduction

• Structuring Element• Erosion• Dilation• Opening• Closing• Outlook: Hit-and-miss Operation, Thinning,

Thickening

Apr 18, 2023 14

Structuring Element (Kernel)• Structuring Elements can have varying sizes• Usually, element values are 0,1 and none(!)• Structural Elements have an origin• For thinning, other values are possible• Empty spots in the Structuring Elements are don’t

care’s!

Apr 18, 2023 15

Box

Disc

Examples of stucturing elements

Dilation & Erosion

• Basic operations

• Are dual to each other:– ErosionErosion shrinks foreground, enlarges

Background

– Dilation enlarges foreground, shrinks background

Apr 18, 2023 16

Erosion

• Erosion is the set of all points in the image, where the structuring element “fits into”.

• Consider each foreground pixel in the input image– If the structuring element fits in, write a “1” at the

origin of the structuring element!

• Simple application of pattern matching• Input:

– Binary Image (Gray value)– Structuring Element, containing only 1s!

Apr 18, 2023 17

Another example of erosion

• White = 0, black = 1, dual property, image as a result of erosion gets darker

Apr 18, 2023 18

Erosion on Gray Value Images

• View gray value images as a stack of binary images!

Apr 18, 2023 19

Erosion on Gray Value Images

• Images get darker!

Apr 18, 2023 20

Counting Coins

• Counting coins is difficult because they touch each other!

• Solution: Binarization and Erosion separates them!

Apr 18, 2023 21

DILATIONDILATION

04/18/23 22

Example: Dilation• Dilation is an important morphological

operation

• Applied Structuring Element:

Apr 18, 2023 23

Dilation

• Dilation is the set of all points in the image, where the structuring element “touches” the foreground.

• Consider each pixel in the input image– If the structuring element touches the foreground

image, write a “1” at the origin of the structuring element!

• Input:– Binary Image

– Structuring Element, containing only 1s!!

Apr 18, 2023 24

Example for Dilation

Apr 18, 2023 25

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1Output Image

111

Example for Dilation

Apr 18, 2023 26

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 0Output Image

111

Example for Dilation

Apr 18, 2023 27

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 0 1Output Image

111

Example for Dilation

Apr 18, 2023 28

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 0 1 1Output Image

111

Example for Dilation

Apr 18, 2023 29

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 0 1 1 1Output Image

111

Example for Dilation

Apr 18, 2023 30

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 0 1 1 1 1Output Image

111

Example for Dilation

Apr 18, 2023 31

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 0 1 1 1 1 1Output Image

111

Example for Dilation

Apr 18, 2023 32

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 0 1 1 1 1 1 1Output Image

111

Another Dilation Example

• Image get lighter, more uniform intensity

Apr 18, 2023 33

Dilation on Gray Value Images

• View gray value images as a stack of binary images!

Apr 18, 2023 34

Dilation on Gray Value Images

• More uniform intensity

Apr 18, 2023 35

Edge Detection

• Edge Detection

1. Dilate input image

2. Subtract input image from dilated image

3. Edges remain!

Apr 18, 2023 36

Opening & Closing

• Important operations

• Derived from the fundamental operations – Dilatation– Erosion

• Usually applied to binary images, but gray value images are also possible

• Opening and closing are dual operations

Apr 18, 2023 37

OPENINGOPENING

04/18/23 38

Opening

• Similar to Erosion– Spot and noise removal– Less destructive

• Erosion next dilation• the same structuring element for both operations.• Input:

– Binary Image– Structuring Element, containing only 1s!

Apr 18, 2023 39

Opening

• Take the structuring element (SE) and slide it around inside each foreground region. – All pixels which can be covered by the SE with the SE

being entirely within the foreground region will be preserved.

– All foreground pixels which can not be reached by the structuring element without lapping over the edge of the foreground object will be eroded away!

• Opening is idempotent: Repeated application has no further effects!

Apr 18, 2023 40

Opening

• Structuring element: 3x3 square

Apr 18, 2023 41

Opening Example

• Opening with a 11 pixel diameter disc

Apr 18, 2023 42

Opening Example

• 3x9 and 9x3 Structuring Element

Apr 18, 2023 43

3*9

9*3

Opening on Gray Value Images

• 5x5 square structuring element

Apr 18, 2023 44

Use Opening for Separating Blobs

• Use large structuring element that fits into the big blobs

• Structuring Element: 11 pixel disc

Apr 18, 2023 45

CLOSINGCLOSING

04/18/23 46

Closing

• Similar to Dilation– Removal of holes– Tends to enlarge regions, shrink background

• Closing is defined as a Dilatation, followed by an Erosion using the same structuring element for both operations.

• Dilation next erosion!• Input:

– Binary Image– Structuring Element, containing only 1s!

Apr 18, 2023 47

Closing

• Take the structuring element (SE) and slide it around outside each foreground region. – All background pixels which can be covered by the SE

with the SE being entirely within the background region will be preserved.

– All background pixels which can not be reached by the structuring element without lapping over the edge of the foreground object will be turned into a foreground.

• Opening is idempotent: Repeated application has no further effects!

Apr 18, 2023 48

Closing

• Structuring element: 3x3 square

Apr 18, 2023 49

Closing Example

• Closing operation with a 22 pixel disc

• Closes small holes in the foreground

Apr 18, 2023 50

Closing Example 1

1. Threshold

2. Closing with disc of size 20

Apr 18, 2023 51 Thresholded closed

Closing Example 2

• Good for further processing: E.g. Skeleton operation looks better for closed image!

52

skeleton of Thresholded

skeleton of Thresholded and next closed

Closing Gray Value Images

• 5x5 square structuring element

Apr 18, 2023 53

Opening & Closing

• Opening is the dual of closing

• i.e. opening the foreground pixels with a particular structuring element

• is equivalent to closing the background pixels with the same element.

Apr 18, 2023 54

HIT and HIT and MISSMISS

04/18/23 55

Hit-and-miss Transform

• Used to look for particular patterns of foreground and background pixels

• Very simple object recognition• All other morphological operations can be

derived from it!!• Input:

– Binary Image– Structuring Element, containing 0s and 1s!!

Apr 18, 2023 56

Hit-and-miss Transform

• Example for a Hit-and-miss Structuring Element• Contains 0s, 1s and don’t care’s.• Usually a “1” at the origin!

Apr 18, 2023 57

Hit-and-miss Transform

• Similar to Pattern Matching:

• If foreground and background pixels in the structuring element exactly match foreground and background pixels in the image, then the pixel underneath the origin of the structuring element is set to the foreground color.

Apr 18, 2023 58

Corner Detection with Hit-and-miss Transform

• Structuring Elements representing four corners

Apr 18, 2023 59

Corner Detection with Hit-and-miss Transform

• Apply each Structuring Element

• Use OR operation to combine the four results

Apr 18, 2023 60

Basic Basic THINNINGTHINNING

04/18/23 61

Thinning

1. Used to remove selected foreground pixels from binary images

2. After edge detection, lines are often thicker than one pixel.

3. Thinning can be used to thin those line to one pixel width.

Apr 18, 2023 62

Definition of Thinning

• Let K be a kernel and I be an image

with 0-1=0!!• If foreground and background fit the structuring

element exactly, then the pixel at the origin of the SE is set to 0

• Note that the value of the SE at the origin is 1 or don’t care!

Apr 18, 2023 63

KIIKI ,HitAndMiss,thin

Example Thinning

Apr 18, 2023 64

We use two Hit-and-miss Transforms

Basic Basic THICKENINGTHICKENING

04/18/23 65

Thickening

• Used to grow selected regions of foreground pixels

• E.g. applications like approximation of convex hull

Apr 18, 2023 66

Definition Thickening

• Let K be a kernel and I be an image

with 1+1=1• If foreground and background match exactly the

SE, then set the pixel at its origin to 1!• Note that the value of the SE at the origin is 0 or

don’t care!

Apr 18, 2023 67

KIIKI ,HitAndMiss,thicken

Example Thickening

Apr 18, 2023 68

PROBLEMSPROBLEMS

04/18/23 69

Problems

1. Consider the images on slide 17! Why are the images getting darker under erosion? Explain!

2. Consider the images on slide 31! Why are the intensities becoming more uniform? Explain!

3. Compare Dilatation and Erosion! How are they related? Verify your answers with Matlab!

4. Apply Erosion and Dilatation for noise removal!

5. Consider slide 38: Remove the artefacts remaining with the horizontal lines.

Apr 18, 2023 70

Problems

6. Derive dilatation and erosion from the Hit-and-miss transformation

Apr 18, 2023 71

Sources Used

Volker Krüger & Rune Andersen

University of Aalborg, Esbjerg

Apr 18, 2023 72

Recommended