Einführung in Visual Computing Unit 18: Morphological Operations Content: Introduction Structuring Element Erosion Dilation Opening Closing Hit‐and‐Miss Thinning http://www.caa.tuwien.ac.at/cvl/teaching/sommersemester/evc 1 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
87
Embed
Unit 18: Morphological Operations - TU Wien...Essential part of morphological operations is the StructuringElement used to probe the input image. Two‐dimensional structuringelements
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Einführung in Visual Computing Unit 18: Morphological Operations
Content: Introduction Structuring Element Erosion Dilation Opening Closing Hit‐and‐Miss Thinning
1 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Introduction
Morphology denotes branch of biology that deals with form and structure of animals and plants.
Same word in the context of Mathematical Morphology: Tool for extracting image components that are useful in representation and description of region shape, such as boundaries, skeletons etc.
Language of Mathematical Morphology is set theory.
Sets in Mathematical Morphology represent objects in image.
Motive: Extract features from shape
2 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Introduction
Morph means “Shape”
We do Morphology for Shape Analysis & Shape Study.
Shape analysis easy in case of binary images, pixel locations describe the shape.
Digital Morphology is a way to describe or analyze the shape of objects in digital images
3 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Introduction
Value of each pixel in the output image is based on a comparisonof the corresponding pixel in the input image with its neighbors.
By choosing size and shape of 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 and greyscale images.
Good for, e.g., Noise removal in background Removal of holes in foreground / background
4 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Basic Concepts From Set Theory
.B xandA x|xBA B, andA of difference The
.Ax|xA A, of complement The.B xandA x|xBA B, andA ofon intersecti The
.Bor xA x|xBA B, andA ofunion The.Ba A,aevery for if B,A written B, ofsubset a isA
A.a A write ofelement an not is a indicate To A.a A write ofelement an is a indicate To
sets. be B andA Let
c
5 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
A
B
A
B
B
A
A
B
BA BA
cA cBABA
A
Examples
6 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Dilation and Erosion
Dilation and Erosion are the two fundamentalmorphological operations.
Dilation adds pixels to the boundaries of objects in an image, while erosion removes pixels on object boundaries.
In morphological dilation and erosion operations, the state of any given pixel in the output image is determined by applying a rule to the corresponding pixel and its neighbors in the input image.
The rule used to process the pixels defines the operation as Dilation or Erosion.
7 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
A first Example: Erosion
Erosion is an important morphological operation
Applied Structuring Element:
8 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Erosion
1 0 0 0 1 1 1 0 1 1Input image
Structuring Element
0Output Image
111
9 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Erosion
1 0 0 0 1 1 1 0 1 1
0 0
111
Input image
Structuring Element
Output Image
10 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Erosion
1 0 0 0 1 1 1 0 1 1
0 0 0
111
Input image
Structuring Element
Output Image
11 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Erosion
1 0 0 0 1 1 1 0 1 1
0 0 0 0
111
Input image
Structuring Element
Output Image
12 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Erosion
1 0 0 0 1 1 1 0 1 1
0 0 0 0 1
111
Input image
Structuring Element
Output Image
13 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Erosion
1 0 0 0 1 1 1 0 1 1
0 0 0 0 1 0
111
Input image
Structuring Element
Output Image
14 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Erosion
1 0 0 0 1 1 1 0 1 1
0 0 0 0 1 0 0
111
Input image
Structuring Element
Output Image
15 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Erosion
1 0 0 0 1 1 1 0 1 1
0 0 0 0 1 0 0 0
111
Input image
Structuring Element
Output Image
16 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Dilation & Erosion
Basic operations
Are dual to each other: Erosion shrinks foreground, enlarges Background
Dilation enlarges foreground, shrinks background
17 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Structuring Element
Structuring Element
Essential part of morphological operations is the Structuring Element used to probe the input image.
Two‐dimensional structuring elements consist of a matrix of 0’s and 1’s, much smaller than the image being processed.
Structuring Elements can have varyingsizes
Element values are 0,1 and none (!) Structural Elements have origin (anchor pixel)
19 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
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.
20 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example of Structuring Elements (Kernels)
Empty spots in the Structuring Elements are don’t care’s!
Box
Disc
21 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Erosion
Erosion
Erosion is the set of all points in the image, where the structuringelement “fits into”.
Consider each foreground pixel in the input image If the structuring element fits in, write a “1” at the origin of the structuring element!
Simple application of pattern matching Input: Binary Image (Gray value) Structuring Element, containing only 1s!
23 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Erosion
Brief Description To delete or to reduce something Pixels matching a given pattern are deleted from the image. Basic effect
Erode away the boundaries of regions of foreground pixels (i.e. white pixels, typically).
Common names: Erode, Shrink, Reduce
24 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Erosion
How It Works A & B are sets in Z², the erosion of A by B, denoted as
In words, this equation indicates that the erosion of A by B is the set of all points z such that B, translated by z, is contained in A.
BA
ABzBA z )(
25 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Erosion
Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations26
%Show the result imagesubplot(1,1,1), imshow(Ierode1), title('11x11 square');
29 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Iterative Operation of Erosion
Original Image after 1 erosion
after 5 erosions after inf erosions
30 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Counting Coins
Counting coins is difficult because they touch each other! Solution: Binarization and Erosion separates them!
31 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Dilation
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!!
33 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Dilation
Brief Description
To expand or to increase something.
Basic effect: Gradually enlarge the boundaries of regions of foreground pixels on a binary image.
Common names: Dilate, Grow, Expand
34 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Dilation
How It Works: A & B are sets in Z², the dilation of A by B, denoted as
This equation is based on obtaining the reflection of B about its origin and shifting this reflection by z.
The dilation of A by B is the set of all displacements z, such that Band A overlap by at least one element. Based on this interpretation the equation can be written as:
BA
AABzBA z )(
35 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Dilation
Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations36
Effect of dilation using a 3×3 square structuring element
37 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Dilation
1 0 0 0 1 1 1 0 1 1
1 0
111
Input image
Structuring Element
Output Image
38 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Dilation
1 0 0 0 1 1 1 0 1 1
1 0 1
111
Input image
Structuring Element
Output Image
39 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Dilation
1 0 0 0 1 1 1 0 1 1
1 0 1 1
111
Input image
Structuring Element
Output Image
40 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Dilation
1 0 0 0 1 1 1 0 1 1
1 0 1 1 1
111
Input image
Structuring Element
Output Image
41 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Dilation
1 0 0 0 1 1 1 0 1 1
1 0 1 1 1 1
111
Input image
Structuring Element
Output Image
42 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Dilation
1 0 0 0 1 1 1 0 1 1
1 0 1 1 1 1 1
111
Input image
Structuring Element
Output Image
43 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example for Dilation
1 0 0 0 1 1 1 0 1 1
1 0 1 1 1 1 1 1
111
Input image
Structuring Element
Output Image
44 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Dilation
Example: Binary dilation (Region Filling) Dilation is also used as the basis for other mathematical morphology operators, often in combination with logical operators.
Region filling is a morphological algorithm
Original image Region filling
45 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Another Dilation Example
Image get lighter, more uniform intensity
46 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
50 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening
Opening & Closing
Important operations Derived from the fundamental operations Dilation Erosion
Usually applied to binary images, but gray value images are also possible
Opening and closing are dual operations
52 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Combining Dilation and Erosion
Morphological Opening Opening is defined as an erosion, followed by a dilation.
Morphological Closing Closing is defined as a dilation, followed by an erosion.
53 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening
Similar to Erosion Spot and noise removal Less destructive
Erosion next Dilation Same structuring element for both operations.
Input: Binary Image Structuring Element, containing only 1s!
54 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening
Take the structuring element and slide it around inside each foreground region. All pixels which can be covered by the SE with the SE being entirely within the foreground region will be preserved.
All foreground pixels which can not be reached by the structuring element without lapping over the edge of the foreground object will be eroded away!
Opening is idempotent: Repeated application has no further effects!
55 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening
Brief Description Opening tends to “open” small gaps or spaces between touching objects in an image.
Opening is also used to remove noise (Pepper noise). The erosion step in an opening will remove isolated pixels as well as boundaries of object and the dilation step will restore most of the boundary pixels without restoring the noise.
Common names: Opening
56 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening
How It works Opening is defined as an erosion followed by a dilation.
Opening is the dual of closing Opening the foreground pixels with a particular structuring element is equivalent to Closing the background pixels with the same element.
BBABA
57 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening
Structuring element: 3x3 square1 1 1
1 1 1
1 1 1
58 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening
Binary Opening Example Separate out the circles from the lines
The lines have been almost completely removed while the circles remain almost completely unaffected.
A mixture of circle and lines Opening with a disk shaped structuring element with 11 pixels in diameter
59 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening Example
Opening with a 9 pixel diameter disc
Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations60
1
1 1 1
1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1
1 1 1
1
Opening Example
3x9 and 9x3 Structuring Element
3*9
9*3
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
61 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening
Binary Opening Example Extract the horizontal and vertical lines separately
There are a few glitches in rightmost image where the diagonal lines cross vertical lines.
These could easily be eliminated, however, using a slightly longer structuring element.
Original image The result of an Opening with 3×9 vertically oriented structuring element
The result of an Opening with 9×3 horizontally oriented
structuring element
62 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
%Apply the open oprationfigure('Name', 'Open');Iopen1 = imopen(I,se1);
%Show the result imagesubplot(1,1,1), imshow(Iopen1), title('11x11 square');
63 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Iterative Operation of Opening
Original Image after 1 opening
after 5 openings after inf openings
64 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Use Opening for Separating Blobs
Use large structuring element that fits into the big blobs Structuring Element: 11 pixel disc
65 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Closing
Closing
Similar to Dilation Removal of holes Tends to enlarge regions, shrink background
Closing is defined as a Dilatation, followed by an Erosion using the same structuring element for both operations.
Dilation next Erosion!
Input: Binary Image Structuring Element, containing only 1s!
67 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Closing
Take the structuring element and slide it around outside each foreground region. All background pixels which can be covered by the SE with the SE being entirely within the background region will be preserved.
All background pixels which can not be reached by the structuring element without lapping over the edge of the foreground object will be turned into a foreground.
Opening is idempotent: Repeated application has no further effects!
68 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Closing
Structuring element: 3x3 square1 1 1
1 1 1
1 1 1
69 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Closing Example
Closing operation with a 22 pixel disc Closes small holes in the foreground
70 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Threshold Closing with disc of size 20
Closing Example
Thresholded closed
71 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
%Apply close operationfigure('Name', ‘Close');Iclose1 = imclose(I,se1);
%Show the result imagesubplot(1,1,1), imshow(Iclose1), title('11x11 square');
Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations72
Iterative Operation of Closing
Original Image after 1 opening
after 5 openings after inf openings
73 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Opening & Closing
Opening is the dual of closing i.e. opening the foreground pixels with a particular structuring element
is equivalent to closing the background pixels with the same element.
74 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Hit and Miss
Hit‐and‐Miss Transform
Used to look for particular patterns of foreground and background pixels
Very simple object recognition All other morphological operations can be derived from it!!
Input: Binary Image Structuring Element, containing 0s and 1s!!
76 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Hit‐and‐Miss Transform
How It Works The structuring element used in the hit‐and‐miss can contain bothforeground and background pixels.
OperationsIf the foreground and background pixels in the structuring elementexactly match foreground and background pixels in the image, thenthe pixel underneath the origin of the structuring element is set tothe foreground color.If it doesn't match, then that pixel is set to the background color.
77 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Hit‐and‐Miss Transform
Effect of the hit‐and‐miss based right angle convex corner detector
Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations78
Four structuring elements used for corner finding in binary images
Hit‐and‐Miss Transform
Guidelines for Use The hit‐and‐miss transform is used to look for occurrences of particular binary patterns.
It can be used to look for several patterns: Simply by running successive transforms using different structuring elements, and then ORing the results together.
The operations of erosion, dilation, opening, closing, thinning and thickening can all be derived from the hit‐and‐miss transform in conjunction with simple set operations.
79 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Hit‐and‐Miss Transform
Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations80
The triple points (points where three lines meet) of the skeleton
Hit‐and‐miss transform outputs single foreground pixels at each triple point
Image was dilated once using a cross‐shaped structuring element in order to mark these isolated points clearly, and this was then ORedwith the original skeleton.
Basic Thinning
Thinning
1. Used to remove selected foreground pixels from binary images
2. After edge detection, lines are often thicker than one pixel.
3. Thinning can be used to thin those line to one pixel width.
82 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Thinning
Brief Description
Remove selected foreground pixels from binary images, somewhat like erosion or opening.
Thinning is normally applied only to binary images.
Common names: Thinning
83 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Thinning
Operation Translate origin of the structuring element to each possible pixel position in the image and compare it with the underlying image pixels.
If foreground and background pixels in the structuring element exactly match foreground and background pixels in the image, then the image pixel underneath the origin of the structuring element is set to background (zero).
Otherwise, it is left unchanged.
Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations84
Thinning
Example: Thinning (character recognition) 1) shows the structuring element used in combination with thinning to obtain the skeleton.
2) was used in combination with thinning to prune the skeleton and with the hit‐and‐miss operator to find the end points of the skeleton.
Each structuring element was used in each of its 45°rotations.
85 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Thinning
A simple way to obtain the skeleton of the character is to thin the image until convergence.The line is broken at some locations, which might cause problems during the recognition process.
Original image Thresholded image Thinning result
86 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations
Example Thinning
We use two Hit‐and‐miss Transforms
87 Robert Sablatnig, Computer Vision Lab, EVC‐18: Morphological Operations