What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word...
Transcript of What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word...
What are Morphological Operations? 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 manipulateobject shapes such as thinning, thickening, and filling.
Binary morphological operations are derived fromset operations.
Basic Set Operations 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.
Translation and Reflection Operations Translation and Reflection Operations
A
(A)z
z = (z1,z2)
Translation Reflection
B̂
B
BbbwwB ∈−== for ,ˆ( ) AazaccA z ∈+== for ,
Logical Operations* Logical Operations*
*For binary images only
Logical Operations* Logical Operations*
Dilation Operations Dilation Operations
φ≠∩=⊕ ABzBA zˆ
AABzBA z ⊆∩=⊕ ]ˆ[
This equation is based on obtaining the reflection of B about its original and shifting this reflection by z. The dilation of A by B the is the set of all displacement, z, such and A overlap by at least one element.
B̂
Set B is commonly referred to as the structuring element.In
Dilation Operations Dilation Operations AABzBA z ⊆∩=⊕ ]ˆ[
Matlab à 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.
Dilation Operations Dilation Operations
φ≠∩=⊕ ABzBA zˆ
φ = Empty set
A = Object to be dilatedB = Structuring element
Dilate means “extend”
Example: Application of DilationExample: Application of Dilation
“Repair” broken characters
Example: Application of DilationExample: Application of Dilation
>> B=[0 1 0; 1 1 1; 0 1 0]B =
0 1 01 1 10 1 0
>> A=imread('fig0905.tif');>> A2=imdilate(A,B);>> imshow(A);>> figure;imshow(A2);
Remember! Dilation is an operation that “grows” or “thickens” objects in a binary image. The specific manner and extent of this thickening is controlled by a shape refer to as a structuring element
Example: Application of DilationExample: Application of DilationRemember! Dilation is an operation that “grows” or “thickens” objects in a binary image. The specific manner and extent of this thickening is controlled by a shape refer to as a structuring element.
Erosion Operation Erosion Operation
( ) ABzBA z ⊆=
A = Object to be erodedB = Structuring element
Erosion means “trim”
A B
The Erosion of A by B is the set of all points z such that B, translated by z is contained in A.
Erosion Operation Erosion Operation
Matlabà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.
Example: Application of Dilation and ErosionExample: Application of Dilation and Erosion
Remove small objects such as noise
Remember! Erosion “shrinks” or “thins” objects in binary image.
Duality Between Dilation and ErosionDuality Between Dilation and Erosion
BABA cc ˆ) ( ⊕=
Proof:where c = complement
( )( )( )
BA
ABz
ABz
ABzBA
c
cz
ccz
cz
c
ˆ
) (
⊕=
≠∩=
=∩=
⊆=
φ
φ
Opening Operation Opening Operation
BBABA ⊕= ) (o
( ) ( ) ABBBA zz ⊆∪=oor
= Combination of all parts of A that can completely contain B
Opening eliminates narrow and small details and corners.
(Images from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Example of Opening Example of Opening
Closing Operation Closing Operation
BBBA )A( ⊕=•
Closing fills narrow gaps and notches
(Images from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Example of Closing Example of Closing
B
Duality Between Opening and ClosingDuality Between Opening and Closing
( ) BABA cc ˆo=•
Properties OpeningProperties Opening
( ) BABBABDBCDC
ABA
ooo
oo
o
=⊂⊂
⊆
.3 then If 2.
.1
( ) BABBABDBCDC
BAA
•=•••⊂•⊂
•⊆
.3 then If 2.
.1Properties ClosingProperties Closing
Idem potent property: can’t change any more
Example: Application of Morphological OperationsExample: Application of Morphological Operations
(Images from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Finger print enhancementf=imread('fig911.tif');se=strel('square',3)fo=imopen(f,se);imshow(fo);foc=imclose(fo,se);figure;imshow(foc);
HitHit--oror--Miss Transformation Miss Transformation
)( XWAXABA c −∩=*
where X = shape to be detectedW = window that can contain X
HitHit--oror--Miss Transformation (cont.) Miss Transformation (cont.)
)( XWAXABA c −∩=*
HitHit--oror--Miss Transformation (cont.) Miss Transformation (cont.) )( XWAXABA c −∩=*
21 BABABA c∩=*
However, if we consider B is a structuring pair, B = (B1, B2) where B1=X and B2 =(W-X). We can rewrite as:
Original Image
Erosion of A by B1
Complement of the original image Ac
Erosion of Ac by B2
Output Image
HitHit--oror--Miss Transformation (cont.) Miss Transformation (cont.) Matlab command
C=bwhitmis(A,B1,B2);
Example:
>>f=imread(‘Fig0913.tif’);
>>B1=strel([0 0 0;0 1 1; 0 1 0]);
>>B2=strel([1 1 1;1 0 0; 1 0 0]);
>>g= bwhitmiss(f,B1,B2);
>>imshow(g);
Boundary Extraction Boundary Extraction
BAAβ(A) −=
Original image
Boundary
The boundary of set A, denoted by , can be obtained by first eroding A by B (suitable structuring element) and then performing the set difference between A and its erosion.
)(Aβ
Boundary Extraction Boundary Extraction
BAAβ(A) −=
Original image
Boundary
A=imread('fig914.jpg');B=strel('square',3)
AeB=imerode(A,B);Bon=A-AeB;imshow(Bon);
Region Filling Region Filling
( ) ckk ABXX ∩⊕= −1
Original image
Results of region filling
where X0 = seed pixel p
Extraction of Connected Components Extraction of Connected Components
( ) ABXX kk ∩⊕= −1 where X0 = seed pixel p
Example: Extraction of Connected Components Example: Extraction of Connected Components
X-ray imageof bones
Thresholdedimage
Connectedcomponents
(Images from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Convex Hull Convex Hull
i
iDAC
=
=4
1)(
4,3,2,1 , 1 =∪= − iABXX ik
ik *
iconv
i XD =
Convex hull has no concave part.
Convex hull
Algorithm: where
convergence
Example: Convex Hull Example: Convex Hull
4,3,2,1 , 1
=∪= −
iABXX i
kik *
Thinning Thinning
cBAABAABA
) ( ) (
∩=
−=⊗ *
*
{ } ))...))((...(( 21 nBBBABA ⊗⊗⊗=⊗
Example: Thinning Example: Thinning
Make an object thinner.
{ } ))...))((...(( 21 nBBBABA ⊗⊗⊗=⊗
Thickening Thickening
* ) ( BAABA ∪=
{ } ) )...) ) ((...(( 21 nBBBABA =
Make an object thicker
*
However, we can do as follow:
1. C=Ac
2. Thin C
3. Form Cc
Skeletons Skeletons
Dot lines are skeletons of thisstructure
Skeleton, S(A), of a set A is:
(a) If z is a point of S(A) and (D)z, is the largest disk centered at z and contained in A, one cannot find a larger disk (not necessarily centered at z) containing (D)z, and included in A. The disk (D)z, is called a maximum disk.
(b) The disk (D), touches the boundary of A at two or more different places.
Skeletons (cont.) Skeletons (cont.)
)()(0
ASAS k
K
k=
=
with
where ...) ) ) (...( ( BBBAkB)A =
BkB)AkB)AASk o ( ()( −=
k times
and ( ) φ≠= kBAkK max
Skeletons Skeletons
Pruning Pruning
{ }BAX ⊗=1
AHXX ∩⊕= )( 23
) ( 1
8
12
k
kBXX
=
= *
314 XXX ∪=
= thinning
= finding end points
= dilation at end points
= Pruned result
Example: Pruning Example: Pruning
Originalimage
Prunedresult
After Thinning3 times
End points
Dilationof end points
(Tables from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Summary of Binary Morphological Operations Summary of Binary Morphological Operations
Summary of Binary Morphological Operations (cont.) Summary of Binary Morphological Operations (cont.)
(Tables from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Summary of Binary Morphological Operations (cont.) Summary of Binary Morphological Operations (cont.)
(Tables from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Summary of Binary Morphological Operations (cont.) Summary of Binary Morphological Operations (cont.)
Basic Types of Structuring ElementsBasic Types of Structuring Elements
x = don’t care
GrayGray--Scale Dilation Scale Dilation
{ }bf DyxDytxsyxbytxsfbf ∈∈−−+−−=⊕ ),(;)(),(|),(),(max
{ }bf DxDxsxbxsfbf ∈∈−+−=⊕ and )(|)()(max2-D Case1-D Case
SubimageOriginal image
Moving window
Max
Output image
GrayGray--Scale Dilation (cont.) Scale Dilation (cont.)
+
Reflectionof B
Structuring element B
Note: B can be any shape and subimage must have the same shape asreflection of B.
GrayGray--Scale ErosionScale Erosion
{ }bf DyxDytxsyxbytxsfbf ∈∈++−++=− ),(;)(),(|),(),(min2-D Case1-D Case { }bf DxDxsxbxsfbf ∈∈+−+=− and )(|)()(min
SubimageOriginal image
Moving window
Min
Output image
GrayGray--Scale Erosion (cont.) Scale Erosion (cont.)
-B
Structuring element B
Note: B can be any shape and subimage must have the same shape as B.
Example: GrayExample: Gray--Scale Dilation and ErosionScale Dilation and ErosionOriginal image After dilation
After erosion
Darker Brighter
GrayGray--Scale OpeningScale Opening
bbfbf ⊕−= )(o
Opening cuts peaks
GrayGray--Scale ClosingScale Closing
bbfbf −⊕=• )(
Closing fills valleys
Example: GrayExample: Gray--Scale Opening and ClosingScale Opening and Closing
Original image After closingAfter opening
Reduce whiteobjects
Reduce darkobjects
GrayGray--scale Morphological Smoothing scale Morphological Smoothing
Smoothing: Perform opening followed by closing
Original image After smoothing
GrayGray--scale Morphological Smoothing scale Morphological Smoothing
Smoothing: Perform opening followed by closing
Morphological Gradient Morphological Gradient
Original image Morphological Gradient
)()( bfbfg −−⊕=
Morphological Gradient Morphological Gradient
)()( bfbfg −−⊕=
TopTop--Hat Transformation Hat Transformation
Original image Results of top-hat transform
)( bffh o−=
TopTop--Hat Transformation Hat Transformation
)( bffh o−=
Example: Texture Segmentation Application Example: Texture Segmentation Application
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
Small blob
Large blob
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
Example: Granulometry Example: Granulometry
Example: Granulometry Example: Granulometry
MatlabMatlab: morphological processing: morphological processing
MatlabMatlab: morphological processing: morphological processing
MatlabMatlab: Create Structural Element: Create Structural ElementSE=strel(‘shape’, parameter)
>>se=strel('diamond',3)
0 0 0 1 0 0 00 0 1 1 1 0 00 1 1 1 1 1 01 1 1 1 1 1 10 1 1 1 1 1 00 0 1 1 1 0 00 0 0 1 0 0 0
Size distribution graph
MatlabMatlab: morphological processing: morphological processingbwmorphMorphological operations on binary imagesSyntaxBW2 = bwmorph(BW,operation)BW2 = bwmorph(BW,operation,n)
MatlabMatlab: : bwmorph
MatlabMatlab: : bwmorph
Original imageSize distribution
graph
Matlab:LabelMatlab:Label connected components in binary imageconnected components in binary imagebwlabelSyntaxL = bwlabel(BW,n)[L,num] = bwlabel(BW,n)DescriptionL = bwlabel(BW,n) returns a matrix L, of the same size as BW, containing labels for the connected objects in BW. n can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects; if the argument is omitted, it defaults to 8.
The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object, the pixels labeled 2 make up a second object, and so on.
[L,num] = bwlabel(BW,n) returns in num the number of connected objects found in BW.
Matlab:LabelMatlab:Label connected components in binary imageconnected components in binary imageExamplesLabel components using 4-connected objects. Notice objects 2 and 3; with 8-connected labeling, bwlabel would consider these a single object rather than two separate objects.BW = [1 1 1 0 0 0 0 0
1 1 1 0 1 1 0 01 1 1 0 1 1 0 01 1 1 0 0 0 1 01 1 1 0 0 0 1 01 1 1 0 0 0 1 01 1 1 0 0 1 1 01 1 1 0 0 0 0 0];
L = bwlabel(BW,4)L =
1 1 1 0 0 0 0 01 1 1 0 2 2 0 01 1 1 0 2 2 0 01 1 1 0 0 0 3 01 1 1 0 0 0 3 01 1 1 0 0 0 3 01 1 1 0 0 3 3 01 1 1 0 0 0 0 0
[r,c] = find(L==2);rc = [r c]rc =
2 53 52 63 6
Matlab:MorphologicalMatlab:Morphological process usagesprocess usages
Examples>> f=imread('rice.png');>> imshow(f);>> figure;imhist(f);>> figure;imshow(f>140);>> se=strel('disk',10);>> fo=imopen(f,se);>> figure;imshow(fo);>> f2=imsubtract(f,fo);>> figure;imshow(f2);>> figure;imhist(f);>> figure;imshow(f2>50);