0% found this document useful (0 votes)
28 views79 pages

Lec14 Morphological Lec

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views79 pages

Lec14 Morphological Lec

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 79

Morphological Image Operations

Oct 26, 2024 1


Dilation and Erosion
• Dilation and erosion are two fundamental
morphological operations.

• Dilation adds pixels to the boundaries of


objects in an image, while erosion removes
pixels on object boundaries.
Understanding Dilation and
Erosion
• In the morphological dilation and erosion
operations, the state of any given pixel in
the output image is determined by applying
a rule to the corresponding pixel and its
neighbors in the input image.
• The rule used to process the pixels defines
the operation as a dilation or an erosion.
Rules for Dilation and Erosion
Operation Rule
Dilation The value of the output pixel is the maximum
value of all the pixels in the input pixel’s
neighborhood. In a binary image, if any of the
pixels is set to the value 1, the output pixel is
set to 1.
Erosion The value of the output pixel is the minimum
value of all the pixels in the input pixel’s
neighborhood. In a binary image, if any of the
pixels is set to 0, the output pixel is set to 0.
Structuring Elements
• An essential part of the dilation and erosion
operations is the structuring element used to
probe the input image.
• Two-dimensional, or flat, structuring
elements consist of a matrix of 0’s and 1’s,
typically much smaller than the image
being processed.
Structuring Elements
• The center pixel of the structuring element, called the origin,
identifies the pixel of interest—the pixel being processed.

• The pixels in the structuring element containing 1’s define the


neighborhood of the structuring element.
Mathematical Morphology
(Dilation, Erosion, Closing, Opening)

• Dilation

Dilation expands the connected sets of 1s of a binary image.

It can be used for

1. growing features

2. filling holes and gaps

7
• Erosion

Erosion shrinks the connected sets of 1s of a binary image.

It can be used for

1. shrinking features

2. Removing bridges, branches and small protrusions

8
Structuring Elements

A structuring element is a shape mask used in


the basic morphological operations.

They can be any shape and size that is


digitally representable, and each has an origin.

box
hexagon disk
something

box(length,width) disk(diameter)
9
Dilation with Structuring Elements

The arguments to dilation and erosion are


1. a binary image B
2. a structuring element S

dilate(B,S) takes binary image B, places the origin


of structuring element S over each 1-pixel, and ORs
the structuring element S into the output image at
the corresponding position.

0000 dilate 0110


1
0110 0111
11
0000 0000
S
B origin BS 10
Erosion with Structuring Elements

erode(B,S) takes a binary image B, places the origin


of structuring element S over every pixel position, and
ORs a binary 1 into that position of the output image only if
every position of S (with a 1) covers a 1 in B.

origin
0 0 1 1 0 0 0 0 0 0
1 erode
0 0 1 1 0 0 0 1 1 0
1
0 0 1 1 0 0 0 1 1 0
1
1 1 1 1 1 0 0 0 0 0

B S B S
11
Opening and Closing

• Closing is the compound operation of dilation followed


by erosion (with the same structuring element)

• Opening is the compound operation of erosion followed


by dilation (with the same structuring element)

12
13
Application:
Gear Tooth Inspection
original
binary
image

detected
defects

14
Connected Components Labeling
Once you have a binary image, you can identify and
then analyze each connected set of pixels.

The connected components operation takes in a binary image


and produces a labeled image in which each pixel has the
integer label of either the background (0) or a component.

original thresholded opening+closing components

15
EROSION

10/26/24 16
A first Example: Erosion
• Erosion is an important morphological
operation

• Applied Structuring Element:

Oct 26, 2024 17


Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0

Oct 26, 2024 18


Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0

Oct 26, 2024 19


Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0

Oct 26, 2024 20


Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0

Oct 26, 2024 21


Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0 1

Oct 26, 2024 22


Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0 1 0

Oct 26, 2024 23


Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0 1 0 0

Oct 26, 2024 24


Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0 1 0 0 0

Oct 26, 2024 25


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!

Box

Disc

Examples of stucturing elements


Oct 26, 2024 26
Dilation & Erosion
• Basic operations
• Are dual to each other:
– Erosion shrinks foreground, enlarges
Background

– Dilation enlarges foreground, shrinks


background

Oct 26, 2024 27


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!

Oct 26, 2024 28


Another example of erosion

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

Oct 26, 2024 29


Erosion on Gray Value Images
• View gray value images as a stack of binary
images!

Oct 26, 2024 30


Erosion on Gray Value Images

• Images get darker!

Oct 26, 2024 31


Counting Coins
• Counting coins is difficult because they
touch each other!
• Solution: Binarization and Erosion
separates them!

Oct 26, 2024 32


DILATION

10/26/24 33
Example: Dilation
• Dilation is an important morphological
operation

• Applied Structuring Element:

Oct 26, 2024 34


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!!
Oct 26, 2024 35
Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1

Oct 26, 2024 36


Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0

Oct 26, 2024 37


Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1

Oct 26, 2024 38


Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1

Oct 26, 2024 39


Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1 1

Oct 26, 2024 40


Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1 1 1

Oct 26, 2024 41


Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1 1 1 1

Oct 26, 2024 42


Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1 1 1 1 1

Oct 26, 2024 43


Another Dilation Example

• Image get lighter, more uniform intensity


Oct 26, 2024 44
Dilation on Gray Value Images
• View gray value images as a stack of binary
images!

Oct 26, 2024 45


Dilation on Gray Value Images

• More uniform intensity

Oct 26, 2024 46


Edge Detection
• Edge Detection
1. Dilate input image
2. Subtract input image from dilated image
3. Edges remain!

Oct 26, 2024 47


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
Oct 26, 2024 48
OPENING

10/26/24 49
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!

Oct 26, 2024 50


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!

Oct 26, 2024 51


Opening
• Structuring element: 3x3 square

Oct 26, 2024 52


Opening Example
• Opening with a 11 pixel diameter disc

Oct 26, 2024 53


Opening Example
• 3x9 and 9x3 Structuring Element

3*9

9*3

Oct 26, 2024 54


Opening on Gray Value Images
• 5x5 square structuring element

Oct 26, 2024 55


Use Opening for Separating
Blobs
• Use large structuring element that fits into
the big blobs
• Structuring Element: 11 pixel disc

Oct 26, 2024 56


CLOSING

10/26/24 57
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!
Oct 26, 2024 58
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!

Oct 26, 2024 59


Closing
• Structuring element: 3x3 square

Oct 26, 2024 60


Closing Example
• Closing operation with a 22 pixel disc
• Closes small holes in the foreground

Oct 26, 2024 61


Closing Example 1
1. Threshold
2. Closing with disc of size 20

Oct 26, 2024


Thresholded closed 62
Closing Example 2
• Good for further processing: E.g. Skeleton
operation looks better for closed image!

skeleton of Thresholded
skeleton of Thresholded and next closed
63
Closing Gray Value Images
• 5x5 square structuring element

Oct 26, 2024 64


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.

Oct 26, 2024 65


HIT and
MISS
10/26/24 66
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!!
Oct 26, 2024 67
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!

Oct 26, 2024 68


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.

Oct 26, 2024 69


Corner Detection with Hit-and-
miss Transform
• Structuring Elements representing four
corners

Oct 26, 2024 70


Corner Detection with Hit-and-
miss Transform
• Apply each Structuring Element
• Use OR operation to combine the four
results

Oct 26, 2024 71


Basic
THINNING
10/26/24 72
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.
Oct 26, 2024 73
Definition of Thinning
• Let K be a kernel and I be an image

thin I , K   I  HitAndMiss I , K 
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!
Oct 26, 2024 74
Example Thinning
We use two Hit-and-
miss Transforms

Oct 26, 2024 75


Basic
THICKENING
10/26/24 76
Thickening
• Used to grow selected regions of
foreground pixels
• E.g. applications like approximation of
convex hull

Oct 26, 2024 77


Definition Thickening
• Let K be a kernel and I be an image

thicken I , K   I  HitAndMiss I , K 
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!
Oct 26, 2024 78
Example Thickening

Oct 26, 2024 79

You might also like