72
Introduction Introduction to to Morphologica Morphologica l Operators l Operators Jun 11, 2022 1

Introduction to Morphological Operators 18-May-151

Embed Size (px)

Citation preview

Page 1: Introduction to Morphological Operators 18-May-151

Introduction to Introduction to Morphological Morphological

OperatorsOperators

Apr 18, 2023 1

Page 2: Introduction to Morphological Operators 18-May-151

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

Page 3: Introduction to Morphological Operators 18-May-151

EROSIONEROSION

04/18/23 3

Page 4: Introduction to Morphological Operators 18-May-151

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

Page 5: Introduction to Morphological Operators 18-May-151

A first Example: Erosion• Erosion is an important morphological

operation

• Applied Structuring Element:

Apr 18, 2023 5

Page 6: Introduction to Morphological Operators 18-May-151

Example for Erosion

Apr 18, 2023 6

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

Structuring Element

0Output Image

111

Page 7: Introduction to Morphological Operators 18-May-151

Example for Erosion

Apr 18, 2023 7

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

Structuring Element

0 0Output Image

111

Page 8: Introduction to Morphological Operators 18-May-151

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

Page 9: Introduction to Morphological Operators 18-May-151

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

Page 10: Introduction to Morphological Operators 18-May-151

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

Page 11: Introduction to Morphological Operators 18-May-151

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

Page 12: Introduction to Morphological Operators 18-May-151

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

Page 13: Introduction to Morphological Operators 18-May-151

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

Page 14: Introduction to Morphological Operators 18-May-151

Introduction

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

Thickening

Apr 18, 2023 14

Page 15: Introduction to Morphological Operators 18-May-151

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

Page 16: Introduction to Morphological Operators 18-May-151

Dilation & Erosion

• Basic operations

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

Background

– Dilation enlarges foreground, shrinks background

Apr 18, 2023 16

Page 17: Introduction to Morphological Operators 18-May-151

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

Page 18: Introduction to Morphological Operators 18-May-151

Another example of erosion

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

Apr 18, 2023 18

Page 19: Introduction to Morphological Operators 18-May-151

Erosion on Gray Value Images

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

Apr 18, 2023 19

Page 20: Introduction to Morphological Operators 18-May-151

Erosion on Gray Value Images

• Images get darker!

Apr 18, 2023 20

Page 21: Introduction to Morphological Operators 18-May-151

Counting Coins

• Counting coins is difficult because they touch each other!

• Solution: Binarization and Erosion separates them!

Apr 18, 2023 21

Page 22: Introduction to Morphological Operators 18-May-151

DILATIONDILATION

04/18/23 22

Page 23: Introduction to Morphological Operators 18-May-151

Example: Dilation• Dilation is an important morphological

operation

• Applied Structuring Element:

Apr 18, 2023 23

Page 24: Introduction to Morphological Operators 18-May-151

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

Page 25: Introduction to Morphological Operators 18-May-151

Example for Dilation

Apr 18, 2023 25

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

Structuring Element

1Output Image

111

Page 26: Introduction to Morphological Operators 18-May-151

Example for Dilation

Apr 18, 2023 26

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

Structuring Element

1 0Output Image

111

Page 27: Introduction to Morphological Operators 18-May-151

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

Page 28: Introduction to Morphological Operators 18-May-151

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

Page 29: Introduction to Morphological Operators 18-May-151

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

Page 30: Introduction to Morphological Operators 18-May-151

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

Page 31: Introduction to Morphological Operators 18-May-151

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

Page 32: Introduction to Morphological Operators 18-May-151

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

Page 33: Introduction to Morphological Operators 18-May-151

Another Dilation Example

• Image get lighter, more uniform intensity

Apr 18, 2023 33

Page 34: Introduction to Morphological Operators 18-May-151

Dilation on Gray Value Images

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

Apr 18, 2023 34

Page 35: Introduction to Morphological Operators 18-May-151

Dilation on Gray Value Images

• More uniform intensity

Apr 18, 2023 35

Page 36: Introduction to Morphological Operators 18-May-151

Edge Detection

• Edge Detection

1. Dilate input image

2. Subtract input image from dilated image

3. Edges remain!

Apr 18, 2023 36

Page 37: Introduction to Morphological Operators 18-May-151

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

Page 38: Introduction to Morphological Operators 18-May-151

OPENINGOPENING

04/18/23 38

Page 39: Introduction to Morphological Operators 18-May-151

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

Page 40: Introduction to Morphological Operators 18-May-151

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

Page 41: Introduction to Morphological Operators 18-May-151

Opening

• Structuring element: 3x3 square

Apr 18, 2023 41

Page 42: Introduction to Morphological Operators 18-May-151

Opening Example

• Opening with a 11 pixel diameter disc

Apr 18, 2023 42

Page 43: Introduction to Morphological Operators 18-May-151

Opening Example

• 3x9 and 9x3 Structuring Element

Apr 18, 2023 43

3*9

9*3

Page 44: Introduction to Morphological Operators 18-May-151

Opening on Gray Value Images

• 5x5 square structuring element

Apr 18, 2023 44

Page 45: Introduction to Morphological Operators 18-May-151

Use Opening for Separating Blobs

• Use large structuring element that fits into the big blobs

• Structuring Element: 11 pixel disc

Apr 18, 2023 45

Page 46: Introduction to Morphological Operators 18-May-151

CLOSINGCLOSING

04/18/23 46

Page 47: Introduction to Morphological Operators 18-May-151

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

Page 48: Introduction to Morphological Operators 18-May-151

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

Page 49: Introduction to Morphological Operators 18-May-151

Closing

• Structuring element: 3x3 square

Apr 18, 2023 49

Page 50: Introduction to Morphological Operators 18-May-151

Closing Example

• Closing operation with a 22 pixel disc

• Closes small holes in the foreground

Apr 18, 2023 50

Page 51: Introduction to Morphological Operators 18-May-151

Closing Example 1

1. Threshold

2. Closing with disc of size 20

Apr 18, 2023 51 Thresholded closed

Page 52: Introduction to Morphological Operators 18-May-151

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

Page 53: Introduction to Morphological Operators 18-May-151

Closing Gray Value Images

• 5x5 square structuring element

Apr 18, 2023 53

Page 54: Introduction to Morphological Operators 18-May-151

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

Page 55: Introduction to Morphological Operators 18-May-151

HIT and HIT and MISSMISS

04/18/23 55

Page 56: Introduction to Morphological Operators 18-May-151

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

Page 57: Introduction to Morphological Operators 18-May-151

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

Page 58: Introduction to Morphological Operators 18-May-151

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

Page 59: Introduction to Morphological Operators 18-May-151

Corner Detection with Hit-and-miss Transform

• Structuring Elements representing four corners

Apr 18, 2023 59

Page 60: Introduction to Morphological Operators 18-May-151

Corner Detection with Hit-and-miss Transform

• Apply each Structuring Element

• Use OR operation to combine the four results

Apr 18, 2023 60

Page 61: Introduction to Morphological Operators 18-May-151

Basic Basic THINNINGTHINNING

04/18/23 61

Page 62: Introduction to Morphological Operators 18-May-151

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

Page 63: Introduction to Morphological Operators 18-May-151

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

Page 64: Introduction to Morphological Operators 18-May-151

Example Thinning

Apr 18, 2023 64

We use two Hit-and-miss Transforms

Page 65: Introduction to Morphological Operators 18-May-151

Basic Basic THICKENINGTHICKENING

04/18/23 65

Page 66: Introduction to Morphological Operators 18-May-151

Thickening

• Used to grow selected regions of foreground pixels

• E.g. applications like approximation of convex hull

Apr 18, 2023 66

Page 67: Introduction to Morphological Operators 18-May-151

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

Page 68: Introduction to Morphological Operators 18-May-151

Example Thickening

Apr 18, 2023 68

Page 69: Introduction to Morphological Operators 18-May-151

PROBLEMSPROBLEMS

04/18/23 69

Page 70: Introduction to Morphological Operators 18-May-151

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

Page 71: Introduction to Morphological Operators 18-May-151

Problems

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

Apr 18, 2023 71

Page 72: Introduction to Morphological Operators 18-May-151

Sources Used

Volker Krüger & Rune Andersen

University of Aalborg, Esbjerg

Apr 18, 2023 72