Image and Multidimensional Signal Processing Colorado School of Mines

advertisement
Colorado School of Mines
Image and Multidimensional
Signal Processing
Professor William Hoff
Dept of Electrical Engineering &Computer Science
Colorado School of Mines
Department of Electrical Engineering and Computer Science
http://inside.mines.edu/~whoff/
Morphological Image Algorithms
2
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Outline
• Morphological algorithms
–
–
–
–
–
Boundary Extraction
Hit or Miss Transform
Region Filling
Skeletonization
Function “bwmorph” in Matlab
• Grayscale morphology
3
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Boundary Extraction
• To find the boundary of a set A, erode
it by a small structuring element B
• Then take the set difference between A
and its erosion
A
A B
A   A B 
 ( A)  A   A B 
• Example
4
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Hit or Miss Transform
• A method to find the location of a shape B1 in an image A
– Erosion of A Ө B1 gives all places where B1 fits in A
• But B1 fits in any sufficiently large shape
• So also require the boundary around the shape, B2 to be
empty
– Erosion of Ac Ө B2 gives all places where B2 fits in empty places
of A
• Then take intersection
A  B   A B1   Ac  B2 
5
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Question:
• Template matching using
cross correlation also finds
shapes.
• How is the hit-or-miss
transform different?
6
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Region Filling
•
•
•
•
Let A be the set of 8connected boundary points of
a region
Start with a point inside the
region
Repeatedly dilate
At each step, set to zero the
points corresponding to the
region boundary
X k   X k 1  B   Ac , k  1,2,3,
•
Stop when no more changes
7
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Skeletonization
• Is the set of all points that are equally distant from
two closest points of the object boundary
• Equivalently, the union of all maximal disk centers
that are contained in the object
• A concise representation of a shape
• Analogy
– Start a fire at the boundary, let it burn inward
– Points where fire is quenched are the skeleton
Object can be
reconstructed as a
union of disks
8
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Matlab Example
• Use function bwmorph(BW, 'skel', Inf);
But results are
sensitive to small
perturbations in
the boundary
9
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Grayscale Morphology
•
•
Instead of binary images, assume we
have gray values f(x,y), where x,y are
integer pixels
Let b(x,y) be the gray level structuring
element
250
b(x,y)
200
150
100
50
•
We will only focus on flat (constant
value) structuring elements
0
0
50
100
150
200
250
Distance along profile
300
350
400
10
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Grayscale Morphology
• Definition of dilation with flat structuring element
 f  b( x, y )  max

f ( x  s, y  t )
( s ,t )b
• Reflect b(s,t), slide it past f(x,y); at each position, take the maximum
of f(x,y) within the window of b(s,t)
b(s,t)
11
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Grayscale Morphology
• Definition of dilation with flat structuring element
 f  b( x, y )  max

f ( x  s, y  t )
( s ,t )b
• Reflect b(s,t), slide it past f(x,y); at each position, take the maximum
of f(x,y) within the window of b(s,t)
b(s,t)
12
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Gray Scale Erosion
• Definition of erosion (with flat SE)
 f  b( x, y)  (min

f ( x  s, y  t )
s ,t )b
• Slide b(s,t) past f(x,y); at each position, take the minimum of f(x,y)
within that window
b(s,t)
13
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Gray Scale Erosion
• Definition of erosion (with flat SE)
 f  b( x, y)  (min

f ( x  s, y  t )
s ,t )b
• Slide b(s,t) past f(x,y); at each position, take the minimum of f(x,y)
within that window
b(s,t)
14
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Example
15
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Opening and Closing
•
Similar to binary case
– Opening is erosion followed
by dilation
– Closing is dilation followed by
erosion
•
f b   f θ b  b
f  b   f  b θ b
Geometric interpretation of
opening
– Push the SE up from below
against the underside of f
– Take the highest values
achieved at every point
Opening removes small,
bright details
Colorado School of Mines
Department of Electrical Engineering and Computer Science
16
Opening and Closing
•
Geometric interpretation of closing
– Push the SE down from above against the topside of f
– Take the lowest values achieved at every point
Closing removes
small, dark details
17
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Top Hat Transform
• Open the image with a structuring element,
subtract it from the original
• Leaves only details smaller than the structuring
element
h  f  ( f  b)
• Matlab example
I = imread('rice.png');
% Pick structuring element larger than a rice grain
background = imopen(I,strel('disk',15));
subplot(1,2,1), imshow(I);
subplot(1,2,2), imshow(background);
I2 = I-background;
figure, imshow(I2, []);
18
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Another example
• Segment the coins from the image
I = imread('pennies.tif');
I = rgb2gray(I);
imshow(I,[]);
% Pick a disk that will just fit inside the pennies
SE = strel('disk', 6, 0);
I2 = imopen(I,SE);
figure, imshow(I2,[]);
% Threshold to get the pennies
B = Iopen > 150;
figure, imshow(B);
L = bwlabel(B);
props = regionprops(L);
figure(1);
for i=1:length(props)
rectangle('Position', props(i).BoundingBox, 'EdgeColor', 'r');
end
Colorado School of Mines
Department of Electrical Engineering and Computer Science
19
Summary / Questions
• Morphological algorithms are a useful set of tools for
extracting features of interest in a binary image,
including
–
–
–
–
–
Finding connected regions
Filtering out very large or very small regions
Finding the boundary of regions
Filling in the interior of regions
Finding the “skeleton” of a region
• Morphological algorithms can be extended to grayscale
images.
– What does “dilation” and “erosion” mean for grayscale?
20
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Download