digital image analysis and processing cpe 0907544cpe 0907544 … · chapter 9 sections :91– 95 di...
TRANSCRIPT
Digital Image Analysis and ProcessingCPE 0907544CPE 0907544
Morphological Image Processing
Chapter 9Sections : 9 1 – 9 5
D I d J f
Sections : 9.1 – 9.5
Dr. Iyad Jafar
Outline
Introduction
Erosion and Dilation
Opening and Closing
B d EBoundary Extraction
Hole FillingHole Filling
Hit-or-Miss Transformation
2
IntroductionMorphology as word describes a branch of biologythat deals with animal and plant structurethat deals with animal and plant structure
In the context of image processing , it refers to aIn the context of image processing , it refers to aset of mathematical tools that can be used to
extract useful description and representation of regionsextract useful description and representation of regionsin images (boundaries, skeletons, convex hull)remove imperfections introduced during segmentationp g g(thinning, regions filling)
Morphological operators can be formulated in anyn-dimensional Euclidean space (binary, gray scale,color)
3
Introduction
Image after segmentation Image after segmentation g g g gand morphological
processing
4
IntroductionA binary image can be considered as a setb id i “bl k” i l ( ith iby considering “black” pixels (with imagevalue “0”) as elements in the set and “white”pixels (with value “1”) as outside the set, orvice versa.
Morphological filters are essentially set operationsMorphological filters are essentially set operations5
Basic Set OperationsLet x, y, z, … represent locations of 2D pixels, e.g. x= (x1, x2), S denotes the complete set of all pixels inan image, let A, B, … represent subsets of SUnion (OR)( )
Intersection (AND)
6
Basic Set OperationsComplement
Translation
ReflectionReflection
7
Structuring ElementsAll morphological operations are based on usingstructuring elements (similar to filter masks)
1 1 1
1 1 1
0 1 0
1 1 1
M h l i l i b d i h
1 1 1
1 1 1
1 1 1
0 1 0
Morphological operations are based moving thestructuring element over the image pixels to check for aHIT or FITHIT or FIT
FIT - all ON pixels in the structuring element cover ONpixels in the imagepixels in the image
HIT - any ON pixel in the structuring element covers anON pixel in the imageON pixel in the image
8
Structuring Elements
B
Structuring Element
AA Fit AC
A – Fit B – Hit C MiC – Miss
9
Structuring ElementsStructuring elements can be of any size and shapeRectangular shapes are usually used with the origin beingat the center pixel
0 0 1 0 01 1 1
1 1 1
1 1 1
0 1 0
1 1 1
0 1 0
0 1 1 1 0
1 1 1 1 1
0 1 1 1 0
Fundamentally morphological image processing is very like
0 0 1 0 0
Fundamentally morphological image processing is very likespatial filteringThe structuring element is moved across every pixel in theg y poriginal image to give a pixel in a new processed imageThe value of this new pixel depends on the operationperformed
10
Structuring Elements0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0 0 0 1 1 10 0 1 1 1 1 1 0 0 0 0 0
0 1 1 1 1 1 1 1 0 0 0 0B
C
1 1 1
1 1 1
1 1 1
0 1 1 1 1 1 1 1 0 0 0 0
0 0 1 1 1 1 1 1 0 0 0 0
Structuring Element 1
0 1 00 0 1 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 1 1 1 1 1 1 0A
0 1 01 1 10 1 0
0 0 0 0 0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0Structuring Element 2
Location Structuring Element 1 Structuring Element 2
A FIT FIT
B HIT FIT
11
B HIT FIT
C HIT HIT
ErosionErosion of image A by structuringl t B i i b A B h th telement B is given by A B such that
A B =f
{ | ( ) }zz B AA BThe structuring element B is
{ | ( ) }z
positioned with its origin at (x, y) andthe new pixel value is determined usingthe new pixel value is determined usingthe rule:
1 , if fits ( , )
0 other iseB A
g x y ⎧⎨⎩
12
0 , otherwise⎩
ErosionExample 9.1Original Image Processed Image
* ** **
* Keep pixels at which the structuring element scores a FIT
Removed Pixels
Structuring Element
structuring element scores a FIT* Erosion shrinks objects Kept Pixels
ErosionExample 9.2
Original image Erosion by 3*3 square structuring
Erosion by 5*5 square structuring
element element
W h I h l 1 f bl k l!Watch out: In these examples a 1 refers to a black pixel!
ErosionExample 9.3
After erosionOriginal image
After erosion with a disc of radius 10
After erosion with a disc of
After erosion with a disc of
radius 20radius 5
What Is Erosion For?
Erosion can split apart joined objects
Erosion can strip away extrusionsp y
DilationDilation of image A by structuringl t B i i b A B h th telement B is given by A B such that
A B =^
{ | ( ) }zz B AA BThe structuring element B is
{ | ( ) }z
positioned with its origin at (x, y) andthe new pixel value is determined usingthe new pixel value is determined usingthe rule:
1 if hiB A⎧ 1 , if hits ( , )
0 otherwiseB A
g x y ⎧⎨⎩
17
0 , otherwise⎩
DilationExample 9.4Original Image Processed Image
* Keep pixels at which the structuring element hits at least
Pixels added to object
Structuring Element
one ON pixel * Dilation enlarges objects
Kept Pixels
DilationExample 9.5
Original image Dilation by 3*3 Dilation by 5*5Original image ysquare structuring
element
Dilation by 5 5 square structuring
element
Watch out: In these examples a 1 refers to a black pixel!
DilationE l 9 6
Original image After dilation
Example 9.6
Structuring element
What Is Dilation For?Dilation can repair breaks
Dilation can repair intrusionsDilation can repair intrusions
OpeningThe opening operation on image A byt t i l t B i d fi dstructuring element B is defined as
A o B = (A B) BA o B (A B) Bin other words, it is erosion followedby dilationGenerally opening is used toGenerally, opening is used toSmooth the contour of an object (inner
)contour)Break narrow paths between large objectsEliminate thin protrusions
22
OpeningExample 9.7
0 0 1 0 0
0 1 1 1 0
1 1 1 1 11 1 1 1 1
0 1 1 1 0
0 0 1 0 0
Original shapeAfter erosion
Structuring Element
Aft dil ti23
After dilation(opening)
ClosingThe closing operation on image A bystructuring element B is defined asstructuring element B is defined as
A • B = (A B) Bin other words, it is dilation followed byerosionerosionGenerally, closing is used toS h h f bj (Smooth the contour of an object (outercontour)Fuse narrow paths between large objectsEliminate thin small holes and fill gaps in thecontour
24
ClosingExample 9.8
0 0 1 0 0
0 1 1 1 0
1 1 1 1 1
0 1 1 1 0
0 0 1 0 0
Original shapeAfter dilation
Structuring Element
Aft i25
After erosion(Closing)
Example 9.9White noise regions removedBlack regions within theBlack regions within the fingerprint have enlarged
Black regions within the fingerprint shrunken But gaps are introducedintroduced between ridges
26
Boundary ExtractionThe boundary of set A denoted by (A) can beobtained by first eroding A by a suitabley g ystructuring element B then perform the setdifference between A and its erosionff
Erosion
27
Boundary ExtractionExample 9.10
Boundary Extraction
Original binary image Boundary detected based on morphological operatorsmorphological operators
28 Structuring element
Hole FillingfA hole may be defined as a background region surrounded
by a connected border of foreground pixels
The algorithm presented here assumes that we know onepixel for each hole in the image
Algorithm
Form an array X0 of the same size as A and initialize it withzeros except locations that correspond to pixels inside theregions to be filled
Apply the following equation iteratively on array X until Xk =Xk-1 to form the filled holes
( ) cX X B AThe original image with filled holes is found by
1( )k kX X B A
A X A29
filled kA X A
Hole FillingExample 9.11
Original, Complement, and Structuring Element
30
Hole FillingExample 9.12
Original One hole filled All holes filled
31
Hit-or-Miss TransformationA basic tool for shape detectionSuppose we have an image A that consists of three objectspp g jC, D, and E and we want to detect the presence of shapeD; assuming we know its shape
Object E50x50
Object C200x100
Obj t DObject D80x80
32Image A
Hit-or-Miss TransformationWe can start by eroding A with a structuring element thathas the same shape as Dhas the same shape as D
One pixel that represents the
center of object D
Structuring element
D
Erosion
objectD
Image A
However, the result may contain parts of larger objects
33
Hit-or-Miss TransformationConsider the complement of A and a new structuringelement that is one pixel thicker than the objectelement that is one pixel thicker than the object
One pixel that represents the center
Structuring element 82x82
Erosionp
of object D
W-D
Complement of A
Note how the center of object D was detected again !
34
Hit-or-Miss TransformationConsider the intersection of the erosion results from theprevious two slidesprevious two slides
Intersection
Object is s ccessf ll l cated !Object is successfully located !Formally, the hit-or-miss transformation on image A todetect some object X is performed bydetect some object X, is performed by
where W is a the object X thickened by one pixel35
Related Matlab Functionsimerode
imdilate
imopen
I lImclose
strelstrel
bwmorphp
36