7 Morphological

Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

Morphological Image Processing

n Binary dilation and erosion


n Set-theoretic interpretation
n Opening, closing, morphological edge detectors
n Hit-miss filter
n Morphological filters for gray-level images
n Cascading dilations and erosions
n Rank filters, median filters, majority filters

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 1
Binary image processing
n Binary images are common
l Intermediate abstraction in a gray-scale/color image analysis system
• Thresholding/segmentation
• Presence/absence of some image property
l Text and line graphics, document image processing
n Representation of individual pixels as 0 or 1, convention:
l foreground, object = 1 (white)
l background = 0 (black)
n Processing by logical functions is fast and simple
n Shift-invariant logical operations on binary images:
“morphological” image processing
n Morphological image processing has been generalized to
gray-level images via level sets

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 2
Shift-invariance
n Assume that digital images f [x,y] and g[x,y] have infinite support

[ x, y ] ∈{,−2,−1,0,1,2,} × {,−2,−1,0,1,2,}
. . . then, for all integers a and b

f [x, y ] Shift- g [x, y ]


invariant
system

f [x - a, y - b ] Shift- g [x - a, y - b ]
invariant
system

n Shift-invariance does not imply linearity (or vice versa).

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 3
Structuring element
n Neighborhood “window” operator
180 degree rotation “structuring element”

{ } {
W f ⎡⎣ x, y ⎤⎦ = f ⎡⎣ x − x′, y − y′ ⎤⎦ : ⎡⎣ x′, y′ ⎤⎦ ∈Π xy }
The “hat” notation indicates
upright structuring element
(i.e., not rotated!)

n Example structuring elements P xy :

5x5 square cross


x x

y y
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 4
Binary dilation (expanding foreground)
{ }
g ⎡⎣ x, y ⎤⎦ = OR ⎡⎣W f ⎡⎣ x, y ⎤⎦ ⎤⎦ := dilate ( f ,W )

y
f [x, y] P xy g[x, y]

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 5
Binary dilation with square structuring element
{ }
g ⎡⎣ x, y ⎤⎦ = OR ⎡⎣W f ⎡⎣ x, y ⎤⎦ ⎤⎦ := dilate ( f ,W )

n Expands the size of


1-valued objects
n Smoothes object
boundaries
n Closes holes and gaps

dilation with dilation with


Original (701x781)
3x3 structuring element 7x7 structuring element

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 6
Binary erosion (shrinking foreground)

y
f [x, y] P xy g[x, y]

Caveat: There is another definition of erosion in the literature, which flips the structuring element, as for dilation.
The Lagunita online videos use that alternative definition. Matlab function imerode uses the definition on this slide.
To the best of our knowledge, there is no such discrepancy defining dilation.

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 7
Binary erosion with square structuring element

n Shrinks the size of


1-valued objects
n Smoothes object
boundaries
n Removes peninsulas,
fingers, and small
objects
erosion with erosion with
Original (701x781)
3x3 structuring element 7x7 structuring element

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 8
Relationship between dilation and erosion

n Duality: erosion is dilation of the background

n But: erosion is not the inverse of dilation

(
f ⎡⎣ x, y ⎤⎦ ≠ erode dilate ( f ,W ) ,W )
≠ dilate ( erode ( f ,W ) ,W )

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 9
Example: blob separation/detection by erosion

Original binary image Erosion by 30x30 Erosion by 70x70 Erosion by 96x96


Circles (792x892) structuring element structuring element structuring element

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 10
Example: blob separation/detection by erosion

Original binary image Erosion by disk-shaped Erosion by disk-shaped Erosion by disk-shaped


Circles (792x892) structuring element structuring element structuring element
Diameter=15 Diameter=35 Diameter=48

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 11
Example: chain link fence hole detection

Original grayscale image Fence thresholded Erosion with 151x151


Fence (1023 x 1173) using Otsu’s method “cross” structuring element

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 12
Set-theoretic interpretation
Continuous (x,y).
n Set of object pixels
{( x, y ) : f ( x, y ) = 1}
Works for discrete [x,y]
F≡ in the same way.

n Background: complement of foreground set


Fc ≡ {( x, y ) : f ( x, y ) = 0}
n Dilation is Minkowski set addition
G = F ⊕ Π xy Commutative and associative!

= {( x + p , y + p ) : ( x, y ) ∈F,( p , p ) ∈Π }
x y x y xy

=  F+ p , p
( )
( )
px , p y ∈Π xy
x y

translation of F by vector px , p y ( )
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 14
Set-theoretic interpretation: dilation

F
x

y P xy

G = F ⊕ Π xy
= {( x + p , y + p ) : ( x, y ) ∈ F,( p , p ) ∈Π }
x y x y xy

=  F+
( p ,p )
( p , p )∈Π
x y xy
x y

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 15
Set-theoretic interpretation: erosion

F x

y P xy
G
Not commutative!
Not associative!
Minkowski set subtraction

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 16
Opening and closing
n Goal: smoothing without size change
Open filter
( )
n

open ( f ,W ) = dilate erode ( f ,W ) ,W


close ( f ,W ) = erode ( dilate ( f ,W ) ,W )
n Close filter

n Open filter and close filter are biased


l Open filter removes small 1-regions
l Close filter removes small 0-regions
l Bias is often desired for enhancement or detection!
n Unbiased size-preserving smoothers

(
close − open ( f ,W ) = close open ( f ,W ) ,W )
open − close ( f ,W ) = open ( close ( f ,W ) ,W )
n close-open and open-close are duals, but not inverses of each other.

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 17
Small hole removal by closing

Original binary mask Dilation Closing 10x10 Difference to original mask


10x10

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 18
Morphological edge detectors

f éë x, y ùû (
dilate f ,W ¹ f ) (
erode f ,W ¹ f ) ( ) (
dilate f ,W ¹ erode f ,W )

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 20
Recognition by erosion
Binary image f
1400

2000

Structuring

44
element W
34

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 21
Recognition by erosion

Structuring

44
element W
34

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 22
Recognition by erosion
Binary image f
1400

2000

Structuring

62
element W
18

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 23
Recognition by erosion

Structuring

62
element W
18

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 24
Hit-miss filter
Binary image f
1400

2000

Structuring Structuring

62
62

element V element W
18 18

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 25
Hit-miss filter

Structuring

62
element V
18

Structuring

62
element W
18

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 26
Morphological filters for gray-level images

n Threshold sets of a gray-level image f [x,y] (aka level sets)


( ) {
Τθ f ⎡⎣ x, y ⎤⎦ = ⎡⎣ x, y ⎤⎦ : f ⎡⎣ x, y ⎤⎦ ≥ θ , } − ∞ < θ < +∞
n Reconstruction of original image from threshold sets

{ (
f ⎡⎣ x, y ⎤⎦ = sup θ : ⎡⎣ x, y ⎤⎦ ∈Τθ f ⎡⎣ x, y ⎤⎦ )}
n Idea of morphological operators for multi-level
(or continuous-amplitude) signals
l Decompose into threshold sets
l Apply binary morphological operator to each threshold set
l Reconstruct via supremum operation
lGray-level operators thus obtained: flat operators
è Flat morphological operators and thresholding are commutative

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 28
Dilation/erosion for gray-level images
n Explicit decomposition into threshold sets not required in practice
n Flat dilation operator: local maximum over window W

{ {
g ⎡⎣ x, y ⎤⎦ = max W f ⎡⎣ x, y ⎤⎦ }} := dilate( f ,W )
n Flat erosion operator: local minimum over window W

n Binary dilation/erosion operators contained as special case

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 29
1-d illustration of erosion and dilation
Structuring element length =

——Dilation
——Erosion
——Original

Structuring element:
horizontal line
Amplitude

Sample no.

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 30
Image example

Original 394 x 305 Dilation 10x10 square Erosion 10x10 square

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 31
Flat dilation with different structuring elements

Original Diamond Disk 20 degree line

9 points 2 horizontal lines

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 32
Example: counting coins

thresholded 1 connected component

Original 20 connected
components

dilation thresholded after dilation

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 33
Example: chain link fence hole detection

Original grayscale image Flat erosion with 151x151 Binarized by Thresholding


Fence (1023 x 1173) “cross” structuring element

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 34
Morphological edge detector

original f dilation g g− f |g-f


g − f| thresholded

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 36
Beyond flat morphological operators
n General dilation operator

{ } {
g ⎡⎣ x, y ⎤⎦ = sup f ⎡⎣ x − α , y − β ⎤⎦ + w ⎡⎣α , β ⎤⎦ = sup w ⎡⎣ x − α , y − β ⎤⎦ + f ⎡⎣α , β ⎤⎦
α ,β α ,β
}
n Like linear convolution, with sup replacing summation, addition replacing multiplication
n Dilation with “unit impulse”

⎧0 α =β =0
d ⎡⎣α , β ⎤⎦ = ⎨
⎩−∞ else
does not change input signal:

{
f ⎡⎣ x, y ⎤⎦ = sup f ⎡⎣ x − α , y − β ⎤⎦ + d ⎡⎣α , β ⎤⎦
α ,β
}

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 37
Flat dilation as a special case
n Find w éëa , b ùû such that

{ }
f ⎡⎣ x, y ⎤⎦ = sup f ⎡⎣ x − α , y − β ⎤⎦ + w ⎡⎣α , β ⎤⎦ = dilate ( f ,W )
α ,β

n Answer:
⎧⎪0 ⎡⎣α , β ⎤⎦ ∈Π xy
w ⎡⎣α , β ⎤⎦ = ⎨
⎪⎩−∞ else

n Hence, write in general

{
g !" x, y #$ = sup f !" x − α , y − β #$ + w !"α , β #$
α ,β
}
= dilate ( f , w) = dilate ( w, f )

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 38
General erosion for gray-level images
n General erosion operator

n Dual of dilation

n Flat erosion contained as a special case

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 39
Cascaded dilations

f dilate ( f , w1 ) dilate ( f , w1 , w2 )

dilate ⎡⎣ dilate ( f , w1 ) , w2 ⎤⎦ = dilate ( f , w)

where w = dilate ( w1 , w2 )

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 40
Cascaded erosions
n Cascaded erosions can be lumped into single erosion

n New structuring element (SE) is not the erosion of one SE


by the other, but dilation.

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 41
Fast dilation and erosion
n Idea: build larger dilation and erosion operators by cascading simple, small
operators
n Example: binary erosion by 11x11 window
Erosion with … Erosion with
1x3 window 1x3 window
Erosion with
5 stages
11x11 window
Erosion with … Erosion with
3x1 window 3x1 window

5 stages

120 AND per pixel 2x10 = 20 AND per pixel

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 42
Rank filters
n Generalisation of flat dilation/erosion: in lieu of min or max value in window,
use the p-th ranked value
n Increases robustness against noise
n Best-known example: median filter for noise reduction
n Concept useful for both gray-level and binary images
n All rank filters are commutative with thresholding

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 44
Median filter
n Gray-level median filter

{ }
g ⎡⎣ x, y ⎤⎦ = median ⎡⎣W f ⎡⎣ x, y ⎤⎦ ⎤⎦ := median ( f ,W )
n Binary images: majority filter

{ }
g ⎡⎣ x, y ⎤⎦ = MAJ ⎡⎣W f ⎡⎣ x, y ⎤⎦ ⎤⎦ := majority ( f ,W )
n Self-duality
median ( f ,W ) = − ⎡⎣ median ( − f ,W ) ⎤⎦

(
majority ( f ,W ) = NOT ⎡⎣ majority NOT ⎡⎣ f ⎤⎦ ,W ⎤⎦ )

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 45
Majority filter: example

Binary image with


3x3 majority filter 20% ‘Salt&Pepper’ noise 3x3 majority filter
5% ‘Salt&Pepper’ noise

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 46
Median filter: example

Original image 5% ‘Salt&Pepper’ noise 3x3 median filtering 7x7 median filtering

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 47
Example: non-uniform lighting compensation

Original image Dilation (local max) Rank filter


1632x1216 pixels 61x61 structuring element 10st brightest pixel
61x61 structuring element

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 48
Example: non-uniform lighting compensation

Background – original image After global thresholding

Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 49

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy