ch9 - morphological image processing

96
Morphological Image Processing Chapter 9

Upload: hasan911

Post on 23-Oct-2015

56 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Ch9 - Morphological Image Processing

Morphological Image Processing

Chapter 9

Page 2: Ch9 - Morphological Image Processing

Introduction

The word morphology commonly denotes a branch of biology that deals with the form and structure of animals and plants.

Therefore, morphological operations are intended to affect the shape of the object

We use mathematical morphology as a tool for extracting image components that are useful in the representation and description of region shape, such as boundaries, skeletons.

intended to affect the shape of the object

Page 3: Ch9 - Morphological Image Processing

Contents

Once segmentation is complete, morphological operations can be used to remove imperfections in the segmented image and provide information on the form and structure of the imagewe will consider:

– What is morphology?– Simple morphological operations– Compound operations– Morphological algorithms

Page 4: Ch9 - Morphological Image Processing

1, 0, Black, White?

Throughout all of the following slides whether 0 and 1 refer to white or black is a little interchangeableAll of the discussion that follows assumes segmentation has already taken place and that images are made up of 0s for background pixels and 1s for object pixelsAfter this it doesn’t matter if 0 is black, white, yellow, green…….

Page 5: Ch9 - Morphological Image Processing

What Is Morphology?

Morphological image processing (or morphology) describes a range of image processing techniques that deal with the shape (or morphology) of features in an imageMorphological operations are typically applied to remove imperfections introduced during segmentation, and so typically operate on bi-level images

Page 6: Ch9 - Morphological Image Processing

Quick Example

Image after segmentation Image after segmentation and morphological processing

Page 7: Ch9 - Morphological Image Processing

Mathematic Morphology• used to extract image components that are useful in

the representation and description of region shape, such as – boundaries extraction– boundaries extraction– skeletons– convex hull– morphological filtering– thinning– pruning

Page 8: Ch9 - Morphological Image Processing

Mathematic Morphology

mathematical framework used for:• pre-processing

– noise filtering, shape simplification, ...• enhancing object structure• enhancing object structure

– skeletonization, convex hull...• Segmentation

– watershed,…• quantitative description

– area, perimeter, ...

Page 9: Ch9 - Morphological Image Processing

Basic Set Theory

Page 10: Ch9 - Morphological Image Processing

Z2 and Z3

• set in mathematic morphology represent objects in an image– binary image (0 = white, 1 = black) : the element – binary image (0 = white, 1 = black) : the element

of the set is the coordinates (x,y) of pixel belong to the object � Z2

• gray-scaled image : the element of the set is the coordinates (x,y) of pixel belong to the object and the gray levels � Z3

Page 11: Ch9 - Morphological Image Processing

Structuring element (SE)

§ small set to probe the image under study§ for each SE, define origo§ shape and size must be adapted to geometric§ shape and size must be adapted to geometricproperties for the objects

the origo is the reference point on which deictic relationships are based.

Page 12: Ch9 - Morphological Image Processing

Structuring Elements, Hits & Fits

B Structuring Element

Fit: All on pixels in the structuring element cover on

AC

structuring element cover on pixels in the imageHit: Any on pixel in the structuring element covers an on pixel in the image

All morphological processing operations are based on these simple ideas

Page 13: Ch9 - Morphological Image Processing

Reflection and Translation

} ,|{ˆ Bfor bbwwB ∈−∈=

} ,|{)( Afor azaccA z ∈+∈= } ,|{)( Afor azaccA z ∈+∈=

Page 14: Ch9 - Morphological Image Processing

Logic Operations

Page 15: Ch9 - Morphological Image Processing

Example:

Page 16: Ch9 - Morphological Image Processing

Basic idea

• in parallel for each pixel in binary image:– check if SE is ”satisfied”– output pixel is set to 0 or 1 depending on used

operationoperation

Page 17: Ch9 - Morphological Image Processing

Fundamental Operations

Fundamentally morphological image processing is very like spatial filteringThe structuring element is moved across every pixel in the original image to give a pixel in a new processed imageThe value of this new pixel depends on the operation performedThere are two basic morphological operations: erosion and dilation

Page 18: Ch9 - Morphological Image Processing

Basic morphological operations

• Erosion

• Dilation• Dilation

• combine to– Opening object

– Closening background

keep general shape but smooth with respect to

Page 19: Ch9 - Morphological Image Processing

Erosion• Erosion is one of the two basic operators in the area of mathematical morphology , the other being dilation.

• It is typically applied to binary image, but there are versions that work on gray scale image. are versions that work on gray scale image.

• The basic effect of the operator on a binary image is to erode away the boundaries of regions of foreground pixels (i.e. white pixels, typically).

• Thus areas of foreground pixels shrink in size, and holes within those areas become larger.

Page 20: Ch9 - Morphological Image Processing

Erosion

Erosion of image f by structuring element s is given by f � sThe structuring element s is positioned with its origin at (x, y) and the new pixel value is determined using the rule:

=otherwise 0

fits if 1),(

fsyxg

Page 21: Ch9 - Morphological Image Processing

Erosion:

• Does the structuring element fit the set?erosion of a set A by structuring element B: all z

in A such that B is in A when origin of B=zin A such that B is in A when origin of B=z

shrink the object

}{ Az|(B)BA z ⊆=−

Page 22: Ch9 - Morphological Image Processing

Erosion

Page 23: Ch9 - Morphological Image Processing

Erosion

}Az|(B){BA z ⊆=−

Page 24: Ch9 - Morphological Image Processing

Effect of erosion using a 3×3 square structuring element

Applications of erosion : Eliminating unwanted detail in an image

Page 25: Ch9 - Morphological Image Processing

Erosion : eliminating irrelevant detail

structuring element B = 13x13 pixels of gray level 1

Page 26: Ch9 - Morphological Image Processing

Erosion Application Example 1

Watch out: In these examples a 1 refers to a black pixel!

Original image Erosion by 3*3 square structuring

element

Erosion by 5*5 square structuring element

Page 27: Ch9 - Morphological Image Processing

Erosion Application Example 2

Original image

After erosion with a disc of radius 10

After erosion with a disc of radius 20

After erosion with a disc of

radius 5

Page 28: Ch9 - Morphological Image Processing

What Is Erosion For?

Erosion can split apart joined objects

Erosion can split apart

Erosion can strip away extrusions

Watch out: Erosion shrinks objects

Erosion can split apart

Page 29: Ch9 - Morphological Image Processing

Erosion, matlab exampleoriginalBW = imread('circles.png'); se = strel('disk',11); erodedBW = imerode(originalBW,se);imshow(originalBW), figure, imshow(erodedBW)

Page 30: Ch9 - Morphological Image Processing

Dilation• Dilation is one of the two basic operators in the area of mathematical morphology , the other being erosion.

• It is typically applied to binary image, but there are versions that work on gray scale image.

• The basic effect of the operator on a binary image is to gradually enlarge the boundaries of regions of foreground pixels (i.e. white pixels, typically).

• Thus areas of foreground pixels grow in sizewhile holes within those regions become smaller.

Page 31: Ch9 - Morphological Image Processing

DilationDilation of image f by structuring element s is given by f sThe structuring element s is positioned with its origin at (x, y) and the new pixel value is

determined using the rule:

=otherwise 0

hits if 1),(

fsyxg

Page 32: Ch9 - Morphological Image Processing

Dilation:

• Does the structuring element hit the set?• dilation of a set A by structuring element B: all z

in A such that B hits A when origin of B=zin A such that B hits A when origin of B=z

• grow the object

}ˆ{ ΦA)Bz|(BA z ≠∩=⊕ ∩

Page 33: Ch9 - Morphological Image Processing

Dilation

Page 34: Ch9 - Morphological Image Processing

Dilation

Page 35: Ch9 - Morphological Image Processing

Dilation

}ˆ{ ΦA)Bz|(BA z ≠∩=⊕

B = structuring element

Page 36: Ch9 - Morphological Image Processing

Effect of dilation using a 3×3 square structuring element

Applications of dilaion : For bridging gaps in an image

Page 37: Ch9 - Morphological Image Processing

An example:

Page 38: Ch9 - Morphological Image Processing

Dilation Example 1

Original image Dilation by 3*3 square structuring

element

Dilation by 5*5 square structuring element

Watch out: In these examples a 1 refers to a black pixel!

Page 39: Ch9 - Morphological Image Processing

Dilation : Bridging gaps

Page 40: Ch9 - Morphological Image Processing

Dilation, matlab examplebw = imread('text.png');se = strel('line',11,90);bw2 = imdilate(bw,se);imshow(bw), title('Original')figure, imshow(bw2), title('Dilated'

Page 41: Ch9 - Morphological Image Processing

useful

• Erosion– removal of structures of certain shape and size,

given by SEgiven by SE• Dilation

– filling of holes of certain shape and size, given by SE

Page 42: Ch9 - Morphological Image Processing

Combining erosion and dilation

• WANTED:– remove structures / fill holes– without affecting remaining parts– without affecting remaining parts

• SOLUTION:• combine erosion and dilation• (using same SE)

Page 43: Ch9 - Morphological Image Processing

Duality

−=⊕ BA)BA( cc

⊕=− BABA c

−=⊕ BA)BA( cc

Page 44: Ch9 - Morphological Image Processing

Compound Operations

More interesting morphological operations can be performed by performing combinations of erosions and dilationsThe most widely used of these compound operations are:

– Opening

– Closing B)BA(BA

B)BA(BA

−⊕=•

⊕−=o

Page 45: Ch9 - Morphological Image Processing

Opening and Closing

· Opening and Closing are morphological operations which are based on dilation and erosion.

· Opening smoothes the contours of objects, breaks narrow isthmuses and eliminates thin breaks narrow isthmuses and eliminates thin protrusions.

· Closing also produces the smoothing of sections of contours but fuses narrow breaks, fills gaps in the contour and eliminates small holes.

· Opening is basically erosion followed by dilationwhile closing is dilation followed by erosion.

Page 46: Ch9 - Morphological Image Processing

How OpeningWorks ?· An opening is defined as an erosion followed by a dilationusing the same structuring element for both operations.

Effect of opening using a 3×3 square structuring element

Page 47: Ch9 - Morphological Image Processing

Opening Operation Opening Operation

BBABA ⊕= ) (o

( ) ( ){ }ABBBA zz ⊆∪=o

or

= Combination of all parts of A that can completely contain B

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Opening eliminates narrow and small details and corners.

Page 48: Ch9 - Morphological Image Processing

Opening effectOriginal Image Processed Image

Structuring Element

Page 49: Ch9 - Morphological Image Processing

Opening example 2

Page 50: Ch9 - Morphological Image Processing

Opening Operation: application

Structuring element is an 11pixel array with a circle shape

Input Image Resultant Image

Page 51: Ch9 - Morphological Image Processing

Opening Operation, matlab example• I = imread('snowflakes.png');figure; imshow(I)

• BW = IM2BW(I); figure; imshow(BW)

• se = strel('disk',3);• I_opened = imopen(BW ,se);• figure, imshow(I_opened)

Page 52: Ch9 - Morphological Image Processing

How Closing Works?

· Grey level closing consists straightforwardly of a grey level dilation followed by a grey level erosion.

· The closing operator therefore requires two inputs: an image to be closed, and a structuring element.

Effect of closing using a 3×3 square structuring element

Page 53: Ch9 - Morphological Image Processing

Closing effectOriginal Image Processed Image

Structuring Element

Page 54: Ch9 - Morphological Image Processing

Closing Operation Closing Operation

BBBA )A( ⊕=•

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Closing fills narrow gaps and notches

Page 55: Ch9 - Morphological Image Processing

Closing example 2:

Page 56: Ch9 - Morphological Image Processing

Application

Structure element is in between the smaller circle and large circle

Page 57: Ch9 - Morphological Image Processing

Closing Operation, matlab example

• originalBW = imread('circles.png');• imshow(originalBW);

• se = strel('disk',10);• closeBW = imclose(originalBW,se);• figure, imshow(closeBW)

Page 58: Ch9 - Morphological Image Processing

Example: Application of Morphological OperationsExample: Application of Morphological Operations

Finger print enhancement

(Images from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Page 59: Ch9 - Morphological Image Processing

Duality Between Opening and ClosingDuality Between Opening and Closing

( ) ( )BABA cc ˆo=•

Properties OpeningProperties Opening

( )BDBCDC

ABA

oo

o

=

⊂⊂

then If 2.

.1

( ) BABBA ooo = .3

( ) BABBA

BDBCDC

BAA

•=••

•⊂•⊂

•⊆

.3

then If 2.

.1Properties ClosingProperties Closing

Idem potent property: can’t change any more

Page 60: Ch9 - Morphological Image Processing

Hit or Miss Transform

Basic operation where all other operatorscan be derived

It Hit or miss transform of A by B is denoted by

A B

The difference is in structure element from others

*

Page 61: Ch9 - Morphological Image Processing

HitHit--oror--Miss Transformation Miss Transformation

where X = shape to be detectedW = window that can contain X

( ) [ ])XW( AX AB A c −∩=* ∩

Page 62: Ch9 - Morphological Image Processing

HitHit--oror--Miss Transformation (cont.) Miss Transformation (cont.)

( ) [ ])XW( AX AB A c −∩=* ∩

Page 63: Ch9 - Morphological Image Processing

• How It Works ?

• The structural elements used for Hit-or-miss transforms are an extension to the ones used with dilation, erosion etc.

• The structural elements can contain both foreground and background pixels, rather than just foreground pixels, i.e. both ones and zeros.

• The structuring element is superimposed over each pixel in the • The structuring element is superimposed over each pixel in the input image, and if an exact match is found between the foreground and background pixels in the structuring element and the image, the input pixel lying below the origin of the structuring element is set to the foreground pixel value. If it does not match, the input pixel is replaced by the background pixel value.

Page 64: Ch9 - Morphological Image Processing

Structuring elements

Example

Page 65: Ch9 - Morphological Image Processing

Boundary Extraction Boundary Extraction

( )BAAβ(A) −=

Original image

Boundary

Page 66: Ch9 - Morphological Image Processing

Region (Hole) Filling Region (Hole) Filling

( ) ckk ABXX ∩⊕= −1

where X0 = seed pixel p

∩ k = 1, 2, 3, …..

The iteration stops at step k if Xk = Xk-1

Original image

Results of region filling

p

Page 67: Ch9 - Morphological Image Processing

Extraction of Connected Components Extraction of Connected Components

( ) ABXX kk ∩⊕= −1

The iteration stops at step k if Xk = Xk-1

∩ k = 1, 2, 3, …..

where X0 = seed pixel p

Page 68: Ch9 - Morphological Image Processing

Example: Extraction of Connected Components Example: Extraction of Connected Components

X-ray imageof bones

ThresholdedThresholdedimage

Connectedcomponents

Page 69: Ch9 - Morphological Image Processing

Convex Hull Convex Hull

Convex hull has no concave part.

Convex hull

i

i

DAC ∪=

=4

1

)(

( ) 4,3,2,1 , 1 =∪= − iABXX ik

ik *

iconv

i XD =Algorithm: where

Page 70: Ch9 - Morphological Image Processing

Example: Convex Hull Example: Convex Hull

Page 71: Ch9 - Morphological Image Processing

Thinning Thinning

cBAA

BAABA

) (

) (

∩=

−=⊗ *

*

{ } ))...))((...(( 21 nBBBABA ⊗⊗⊗=⊗

Page 72: Ch9 - Morphological Image Processing

Example: Thinning Example: Thinning

Make an object thinner.

Page 73: Ch9 - Morphological Image Processing

Thickening Thickening

* ) ( BAABA ∪=.

{ } ) )...) ) ((...(( 21 nBBBABA =. . . .*

Make an object thicker

Page 74: Ch9 - Morphological Image Processing

Skeletons Skeletons

Dot lines are skeletons of thisstructurestructure

Page 75: Ch9 - Morphological Image Processing

Skeletons (cont.) Skeletons (cont.)

)()(0

ASAS k

K

k∪=

=

with BkB)AkB)AASk o ( ()( −=

where ...) ) ) (...( ( BBBAkB)A =

k times

and ( ){ }φ≠= kBAkK max

Page 76: Ch9 - Morphological Image Processing

Skeletons Skeletons

Page 77: Ch9 - Morphological Image Processing

Pruning Pruning

{ }BAX ⊗=1

AHXX ∩⊕= )( 23

) ( 1

8

12

k

k

BXX ∪=

= *

= thinning

= finding end points

= dilation at end points

314 XXX ∪= = Pruned result

Page 78: Ch9 - Morphological Image Processing

Example: Pruning Example: Pruning

Originalimage

After Thinning End

Prunedresult

Thinning3 times

End points

Dilationof end points

Page 79: Ch9 - Morphological Image Processing

Summary of Binary Morphological Operations Summary of Binary Morphological Operations

Page 80: Ch9 - Morphological Image Processing

Summary of Binary Morphological Operations (cont.) Summary of Binary Morphological Operations (cont.)

Page 81: Ch9 - Morphological Image Processing

Summary of Binary Morphological Operations (cont.) Summary of Binary Morphological Operations (cont.)

Page 82: Ch9 - Morphological Image Processing

Summary of Binary Morphological Operations (cont.) Summary of Binary Morphological Operations (cont.)

Page 83: Ch9 - Morphological Image Processing

Basic Types of Structuring ElementsBasic Types of Structuring Elements

x = don’t care

Page 84: Ch9 - Morphological Image Processing

GrayGray--Scale Dilation Scale Dilation

{ }bf DyxDytxsyxbytxsfbf ∈∈−−+−−=⊕ ),(;)(),(|),(),(max

{ }bf DxDxsxbxsfbf ∈∈−+−=⊕ and )(|)()(max2-D Case

1-D Case

Page 85: Ch9 - Morphological Image Processing

SubimageOriginal image

Moving

Max

GrayGray--Scale Dilation (cont.) Scale Dilation (cont.)

+

Reflectionof B

window

Output image

Structuring element B

Note: B can be any shape and subimage must have the same shape asreflection of B.

Page 86: Ch9 - Morphological Image Processing

GrayGray--Scale ErosionScale Erosion

{ }bf DyxDytxsyxbytxsfbf ∈∈++−++=− ),(;)(),(|),(),(min2-D Case

1-D Case { }bf DxDxsxbxsfbf ∈∈+−+=− and )(|)()(min

Page 87: Ch9 - Morphological Image Processing

SubimageOriginal image

Moving

Min

GrayGray--Scale Erosion (cont.) Scale Erosion (cont.)

-B

Moving window

Output image

Structuring element B

Note: B can be any shape and subimage must have the same shape as B.

Page 88: Ch9 - Morphological Image Processing

Example: GrayExample: Gray--Scale Dilation and ErosionScale Dilation and ErosionOriginal image After dilation

After erosion

Darker Brighter

Page 89: Ch9 - Morphological Image Processing

GrayGray--Scale OpeningScale Opening

bbfbf ⊕−= )(o

Opening cuts peaks

Page 90: Ch9 - Morphological Image Processing

GrayGray--Scale ClosingScale Closing

bbfbf −⊕=• )(

Closing fills valleys

Page 91: Ch9 - Morphological Image Processing

Example: GrayExample: Gray--Scale Opening and ClosingScale Opening and Closing

Original image After closingAfter opening

Reduce whiteobjects

Reduce darkobjects

Page 92: Ch9 - Morphological Image Processing

GrayGray--scale Morphological Smoothing scale Morphological Smoothing

Smoothing: Perform opening followed by closing

Original image After smoothing

Page 93: Ch9 - Morphological Image Processing

Morphological Gradient Morphological Gradient

)()( bfbfg −−⊕=

Original image Morphological Gradient

Page 94: Ch9 - Morphological Image Processing

TopTop--Hat Transformation Hat Transformation

)( bffh o−=

Original image Results of top-hat transform

Page 95: Ch9 - Morphological Image Processing

Example: Texture Segmentation Application Example: Texture Segmentation Application

Small blob

Algorithm:1. Perform closing on the image by using successively larger structuring elements until small blobs are vanished.2. Perform opening to join large blobs together3. Perform intensity thresholding

Original image Segmented result

Large blob

Page 96: Ch9 - Morphological Image Processing

Example: Granulometry Example: Granulometry Objective: to count the number of particles of each sizeMethod:1. Perform opening using structuring elements of increasing size2. Compute the difference between the original image and the result

after each opening operation3. The differenced image obtained in Step 2 are normalized and used

to construct the size-distribution graph.

Original imageSize distribution

graph