You are on page 1of 59

Morphological Image

Processing and Segmentation


Unit 3
Morphological Image Processing and
Segmentation
Morphological Image Processing
• Preliminaries
• Dilation and Erosion
• Opening and Closing
• The Hit-or-Miss Transformation
• Some Basic Morphological Algorithms
Image Segmentation
• Detection of Discontinuities
• Edge Linking and Boundary Detection
• Thresholding and Region-Based Segmentation
Morphology
• Morphology deals with form and structure

• Mathematical morphology is a tool for extracting


image components useful in:

– representation and description of region shape (e.g.


boundaries)

– pre- or post-processing (filtering, thinning, etc.)


• Based on set theory
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 image
Morphological operations are typically applied
to remove imperfections introduced during
segmentation, and so typically operate on bi-
level images
Overview
• Morphology is a technique of image processing
based on shapes. The value of each pixel in the
output image is based on a comparison of the
corresponding pixel in the input image with its
neighbors. By choosing the size and shape of the
neighborhood, you can construct a morphological
operation that is sensitive to specific shapes in the
input image.
• Morphologic operations are especially suited to the
processing of binary images and greyscale images.
What are Morphological Operations?

Morphological operations come from the word “morphing”


in Biology which means “changing a shape”.

Morphing

Image morphological operations are used to manipulate


object shapes such as thinning, thickening, and filling.

Binary morphological operations are derived from


set operations.
In general; what is “Morphology”?

• The science of form and structure


– the science of form, that of the outer form, inner structure, and
development of living organisms and their parts
– about changing/counting regions/shapes
• Among other applications it is used to pre- or post-process
images
– via filtering, thinning and pruning
• Smooth region edges
– create line drawing of face
• Force shapes onto region edges
– curve into a square • Count regions (granules)
– number of black regions
• Estimate size of regions
– area calculations
Goals of morphological operations:

 1. Simplifies image data


 2. Preserves essential shape characteristics
 3. Eliminates noise
 4. Permits the underlying shape to be identified
and optimally reconstructed from their distorted,
noisy forms
Uses of Mathematical Morphology

• image enhancement • shape analysis


• image segmentation • image compression
• image restoration • component analysis
• edge detection • curve filling
• texture analysis • general thinning
• particle analysis • feature detection
• feature generation • noise reduction
• skeletonization • space-time filtering
Morphological operations and algebra

1. Different definitions in the textbooks


2. Different implementations in the image processing programs.
3 The original definition, based on set theory, is made by J. Serra in
1982.
4. Defined for binary images - binary operations (boolean, set-
theoretical)
5. Can be used on grayscale images - multiple-valued
Binary Morphology

• Morphological operators are used to prepare binary


(thresholded) images for object segmentation/recognition
– Binary images often suffer from noise (specifically salt-
and-pepper noise)
– Binary regions also suffer from noise (isolated black pixels
in a white region). Can also have cracks, picket fence
occlusions, etc.
• Dilation and erosion are two binary morphological operations
that can assist with these problems.
Goals of morphological operations

1. Simplifies image data


2. Preserves essential shape characteristics
3. Eliminates noise
4. Permits the underlying shape to be identified
and optimally reconstructed from their distorted,
noisy forms
Importance of Shape in Processing and Analysis

 Shape is a prime carrier of information in machine vision


 For instance, the following directly correlate with shape:
 identification of objects
 object features
 assembly defects
Quick Example

Image after segmentation Image after segmentation and


morphological processing
Basic Set Operations
Concept of a set in binary image morphology:
Each set may represent one object. Each pixel (x,y) has
its status: belong to a set or not belong to a set.

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
Translation and Reflection Operations
Translation Reflection
 A z   c c  a  z , for a  A Bˆ   w w  b, for b  B

B
A

z = (z1,z2)

(A)z B̂
Morphological Image Processing
Basic Morphological Operations
• Dilation – improves the connectivity thereby
reducing the holes
• Erosion - separates the object boundaries
thereby expanding the holes
• Opening – Erosion followed by Dilation
• Closing – Dilation followed by Erosion
All operations require a structuring element
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.
Libraries of Structuring Elements

• Application
specific
structuring
elements
created by
the user
Structuring Element
The two most common structuring elements (given a Cartesian grid)
are the 4-connected and 8-connected sets, N4 and N8. They are
illustrated in Figure .
Definition of Structuring Element(SE):

A structuring element is simply a binary image (or mask) that


allows us to define arbitrary neighborhood structures

Figure: The standard structuring


elements N4 and N8.
Morphological Image Processing and Segmentation

Morphological Image Processing


• Preliminaries
• Dilation and Erosion
• Opening and Closing
• The Hit-or-Miss Transformation
• Some Basic Morphological Algorithms
Image Segmentation
• Detection of Discontinuities
• Edge Linking and Boundary Detection
• Thresholding and Region-Based Segmentation
Dilation and Erosion
• Dilation- adds pixels to the object boundaries,
reduces holes
• Erosion – removes pixels on object
boundaries, separates objects.
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!!
Example for Dilation

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

Structuring Element 1 1 1

Output Image 1

26
Example for Dilation

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

Structuring Element 1 1 1

Output Image 1 0

4/13/20 27
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

4/13/20 28
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
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
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
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
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
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 1110


1
0110 0110
11
0000 0000
S
B origin BS
Example: Dilation
• Dilation is an important morphological
operation

• Applied Structuring Element:


Dilation Operations (cont.)
Reflection B̂

Structuring
Element (B)

Original image (A) Intersect pixel Center pixel


Dilation Operations (cont.)

Result of Dilation Boundary of the “center pixels”


 
where B̂ z intersects A
Structuring Elements

Figure 1 Some example structuring elements.


Fundamental Definitions – Erosion and Dilation

While either set A or B can be thought of as an "image", A is


usually considered as the image and B is called a structuring
element. The structuring element is to mathematical
morphology what the convolution kernel is to linear filter
theory.

Dilation, in general, causes objects to dilate or grow in size;


erosion causes objects to shrink. The amount and the way that
they grow or shrink depend upon the choice of the structuring
element. Dilating or eroding without specifying the structural
element makes no more sense than trying to lowpass filter an
image without specifying the filter.
Dilation
B:structuring
element
A B   z ( Bˆ )  A   
z
Dilation: another formulation
A B   z ( Bˆ )  A  A
z
Explanation of Dilation
Dilation : x = (x1,x2) such that if we center B on them,
then the translated B intersects X.

X difference

dilation
B
Dilation Example

Change a background pixel to foreground if it has a


foreground pixel as a 4-neighbor.
Notation for Dilation
Dilation : x = (x1,x2) such that if we center B on them,
then the so translated B intersects X.

How to formulate this definition ?

1) Literal translation

Mathematical definition of dilation


Another View at Dilation
Dilation :

Dilation

Dilation
Structuring Elements, Hits, Fits and Misses

B Structuring Element

Fit: All on pixels in the structuring


element cover on pixels in the
image
A Hit: Any on pixel in the structuring
C element covers an on pixel in the
image
Miss: All pixels in the structuring
element are not part of the image

All morphological processing operations are based on these simple


ideas
Structuring Elements
Structuring elements can be any size and make
any shape
However, for simplicity we will use rectangular
structuring elements with their origin at the
middle pixel
0 0 1 0 0
1 1 1 0 1 0 0 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1
1 1 1 0 1 0 0 1 1 1 0
0 0 1 0 0
Fitting & Hitting and Missing
0 0 0 0 0 0 0 0 0 0 0 0
1 1 1
0 0 0 1 1 0 0 0 0 0 0 0
1 1 1
0 0 1 B1 1 1 1 0 C0 0 0 0
1 1 1
0 1 1 1 1 1 1 1 0 0 0 0 Structuring
0 1 1 1 1 1 1 1 0 0 0 0 Element 1

0 0 1 1 1 1 1 1 0 0 0 0 0 1 0
0 0 1 1 1 1 1 1 1 0 0 0 1 1 1
0 0 1 1 1 1 1 A1 1 1 1 0 0 1 0
0 0 0 0 0 1 1 1 1 1 1 0 Structuring
Element 2
0 0 0 0 0 0 0 0 0 0 0 0
Dilation
Dilation of image f by structuring element s is
given by f  s
The structuring element s is positioned with its
origin at (x, y) and the new pixel value is
determined using the rule:
1 if s hits f
g ( x, y )  
0 otherwise
Dilation Example
Original Image Processed Image

Structuring Element
Dilation Example
Original Image Processed Image With Dilated Pixels

Structuring Element
Dilation Example 1

Original image Dilation by 3*3 Dilation by 5*5


square structuring square structuring
element element

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


Dilation Example 2
Original image After dilation

Structuring element
What Is Dilation For?
Dilation can repair breaks

Dilation can repair intrusions

Watch out: Dilation enlarges objects


9. x6 A binary array that represents a portion of a black
and white image is given below. Perform the operations
listed below on this piece of image. Assume that all of the
pixels that surround this segment contain black background.
0 0 0 0 0 0 0
0 0 1 1 0 0 0
0 0 0 1 0 0 0
0 0 0 1 1 0 0
0 0 1 1 1 1 0
0 0 1 1 1 0 0
0 1 0 1 0 1 0
0 0 0 0 0 0 0

a) Dilation with the structuring element The origin is shown with


a circled element.
b) Erode with the structuring element
Solution:
(a) The reflected structuring element is
1 1 1

0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0
0 0 1 1 1 1 0
0 0 0 1 0 0 0
0 0 0 1 1 1 0
0 0 0 1 1 0 0
0 0 0 1 1 1 1
0 0 1 1 1 1 0
0 0 1 1 1 1 1 0 0 1 1 1 0 0
0 0 1 1 1 1 1 0 1 0 1 0 1 0
0 1 1 1 1 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0

Input
(b) The erosion using structuring element
1 1
1

0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 1 0 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
(c ) Dilate with the structuring element
11 1
0 1
Reflected structuring element

1 0
1 11

Result of dilation 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 0 0 0 0 1 1 0 0 0
0 0 0 1 1 0 0 0 0 0 1 0 0 0
0 0 0 1 1 0 0
0 0 0 1 1 1 0
0 0 1 1 1 1 0
0 0 1 1 1 1 1
0 0 1 1 1 0 0
0 0 1 1 1 1 1
0 1 0 1 0 1 0
0 1 1 1 1 1 1
0 0 0 0 0 0 0
0 1 1 1 1 1 1

Input
(d) Erode with structuring element 1

0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 1 1 0 0 0
0 0 0 1 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 0 0 0 1 1 1 1 0
0 0 1 1 1 0 0
0 1 0 1 0 1 0
0 0 0 0 0 0 0

You might also like