Post on 29-Dec-2019
transcript
Morphological Image Processing ILecture 07
Milan Gavrilovicmilan@cb.uu.se
Centre for Image AnalysisUppsala University
Computer Assisted Image Analysis2009-04-20
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 1 / 39
Reading InstructionsChapters for this lecture
Chapter 9.1− 9.5.4 in Gonzales-Woods.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 2 / 39
Previous Lectures
Image processingPoint processing (Spatial domain, pixel-wise)Local neighbourhoods (Spatial domain, filtering)Fourier transform (Frequency domain, filtering)
Image analysisSegmentation and labeling
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 3 / 39
MorphologyForm and structure
Mathematical framework used for:Pre-processing
I Noise filtering, shape simplification, ...
Enhancing object structureSegmentationQuantitative description
I Area, perimeter, ...
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 4 / 39
Some set theory
A is a set in Z2.If a = (a1, a2) is an element in A: a ∈ A.If a = (a1, a2) is not an element in A: a 6∈ A.Empty set: ∅.Set specified using { }, e.g.,C = {w|w = −d, ∀ d ∈ D}.Every element in A is also in B (subset): A ⊆ B.Union of A and B:C = A ∪ B = {c|c ∈ A or c ∈ B}.Intersection of A and B:C = A ∩ B = {c|c ∈ A and c ∈ B}.Disjoint/mutually exclusive: A ∩ B = ∅.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 5 / 39
Some more set theory
Complement of A: AC = {w|w 6∈ A}.Difference of A and B:A− B = {w|w ∈ A, w 6∈ B} = A ∩ BC.Reflection of A: A = {w|w = −a, ∀ a ∈ A}.Translation of A by a point z = (z1, z2):(A)Z = {c|c = a + z, ∀ a ∈ A}.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 6 / 39
Logical operationsPixel-wise combination of images (AND, OR, NOT, XOR)
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 7 / 39
Structuring element (SE)
Small set to probe the image under study.For each SE, define an origin:
I SE in point p; origin coincides with p.
Shape and size must be adapted to geometric properties for theobjects.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 8 / 39
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 operation.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 9 / 39
How to describe the SEPossible in many different ways!Information needed:
Position of origin for SE.Position of elements belonging to SE.
N.b.Matlab assumes it’s centre element to be the origin!
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 10 / 39
Five binary morphological transforms
Erosion.⊕ Dilation.◦ Opening.• Closing.⊗ Hit-or-Miss transform.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 11 / 39
Erosion (shrinking)
Does the structuring element fit the set?
Erosion of a set X by structuring element B, εB(X) : all x in X such thatB is in X when origin of B = x.
εB(X) = {x|Bx ⊆ X}.
Gonzalez-Woods:X B = {x|(B)x ⊆ X}.
Shrink the object.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 12 / 39
Example: erosion (fill in!)
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 13 / 39
⊕ Dilation (growing)
Does the structuring element hit the set?
Dilation of a set X by structuring element B, δB(X) : all x in X such thatthe reflection of B hits X when origin of B = x.
δB(X) = {x|(B)x ∩ X 6∈ ∅}.
Gonzalez-Woods:X ⊕ B = {x|(B)x ∩ X 6∈ ∅}.
Grow the object.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 14 / 39
Example: dilation (fill in!)
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 15 / 39
Different SE give different results
Set A.Square structuringelement (dot is thecentre).Dilation of A by B,shown shaded.Elongated structuringelement (dot is thecentre).Dilation of A using thiselement.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 16 / 39
Duality
Erosion and dilation are dual with respect to complementation andreflection,
(A B)C = AC ⊕ B.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 17 / 39
UsefulErosionRemoval of structures of certain shape and size, given by SE(structure element).
Example 3× 3 SE
DilationFilling of holes of certain shape and size, given by SE.
Example 3× 3 SEM. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 19 / 39
Examples
Erosion: SE =square of size13× 13.
Input: squares of size 1× 1,3× 3, 5× 5, 7× 7, 9× 9, and15× 15 pixels.
Dilation oferosionresult: SE =square of size13× 13.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 20 / 39
Use dilation to bridge gaps of broken segments
1 Sample text ofpoor resolutionwith brokencharacters(magnifiedview).
2 Structuringelement.
3 Dilation of (1) by(2).
4 Brokensegments werejoined.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 21 / 39
Use dilation to bridge gaps of broken segments
Wanted:Remove structures/fill holes without affecting remaining parts.
Solution:Combine erosion and dilation (using same SE).
◦ Opening.• Closing.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 22 / 39
◦ Opening
Erosion followed by dilation, denoted ◦.
A ◦ B = (A B)⊕ B.
Eliminates protrusions.Break necks.Smooths contour.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 23 / 39
Example opening (fill in!)
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 24 / 39
Opening: roll ball (=SE) inside objectSee B as a “rolling ball”
Boundary of A • B are equal to points in B that reaches closest to theboundary A when B is rolled inside A.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 25 / 39
• Closing
Dilation followed by erosion, denoted •.
A • B = (A⊕ B) B
Smooth contour.Fuse narrow breaks and long thin gulfs.Eliminate small holes.Fill gaps in the contour.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 26 / 39
Example closing (fill in!)
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 27 / 39
Closing: roll ball (=SE) outside object(Fill in border after closing with ball as SE!)
Boundary of A ◦ B are equal to points in B that reaches closest to theboundary of A when B is rolled outside A.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 28 / 39
⊗ hit-or-miss transformation (⊗ or HMT)
Find location of one shape among a set of shapes (“templatematching”).
A⊗ B = (A B1) ∩ (AC B2)
Composite SE: Object part (B1) and background (B2).
Does B1 fit the object while, simultaneously, B2 misses the object, i.e.,fit the background.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 29 / 39
Hit-or-miss transformation (⊗ or HMT)
Find location of one shape among a set of shapes.
A⊗ B = (A X) ∩(AC (W − X)
)
Alternative:A⊗ B = (A B1) ∩ (AC B2)
= (A B1) ∩ (A⊕ B2)C
= (A B1)− (A⊕ B2)
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 30 / 39
Example hit-or-miss transform (fill in!)
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 31 / 39
Basic morphological algorithms
Use erosion, dilation, opening, closing, hit-or-miss transform for
Boundary extraction.Region filling.Extraction of connected components (labeling).Defining the convex hull.Defining the skeleton.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 32 / 39
Boundary extractionby erosion and set difference (boundary of A = β(A))
Extract theboundary of:
β(A) =A− (A B).
8-connected boundaryβ(A) = pixels with edge
neighbour in AC.
4-connected boundaryβ(A) = pixels with edge or
point neighbour in AC.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 33 / 39
Region filling
Fill a region A given its boundary β(A).x = X0 is known and inside β(A).
Xk = (Xk−1 ⊕ B) ∩ AC, k = 1, 2, 3, ...
Continue until Xk = Xk−1.Filled region A ∪ Xk.
Use to fill holes! Conditional dilation!
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 34 / 39
Example of region filling
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 35 / 39
Compare with removing holes using two-pass labelingalgorithmSee segmentation lecture
Connected component labelingLabel the inverse image.Remove connected components touching the image border.Output = holes + original image.
→ 2 scans + 1 scan (straight forward...)
Mathematical morphologyIterate: dilation, set intersection
→ Dependent on size and shape of the hole needed: initialization!
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 36 / 39
Convex hull
Region R is convex ifI For any points x1, x2 ∈ R, straight line between x1 and x2 is in R.
Convex hull H of a region RI Smallest convex set containing R.
Convex deficiency D = H − R.
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 37 / 39
Convex hull - alternative approachby Gunilla Borgefors, CBA
Count the number of neighbours ofa pixel, if more than three, mark thepixel! Repeat until none of thepixels has more than threeneighbours.Homework - fill in!
M. Gavrilovic (Uppsala University) L07 Morphological Image Processing I 2009-04-20 38 / 39