image and multidimensional signal processing - inside...
TRANSCRIPT
Colorado School of Mines Department of Electrical Engineering and Computer Science Colorado School of Mines Department of Electrical Engineering and Computer Science
Colorado School of Mines
Image and Multidimensional Signal Processing
Professor William Hoff
Dept of Electrical Engineering &Computer Science
http://inside.mines.edu/~whoff/
Colorado School of Mines Department of Electrical Engineering and Computer Science
Morphological Image Algorithms
2
Colorado School of Mines Department of Electrical Engineering and Computer Science 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 Colorado School of Mines Department of Electrical Engineering and Computer Science
Boundary Extraction
BAAA )(
• 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
• Example
BAA A BA
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
21 BABABA c
5
Colorado School of Mines Department of Electrical Engineering and Computer Science 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 8-
connected 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
• Stop when no more changes
,3,2,1,1 kABXX c
kk
7
Colorado School of Mines Department of Electrical Engineering and Computer Science 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 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
• We will only focus on flat (constant
value) structuring elements
b(x,y)
0 50 100 150 200 250 300 350 4000
50
100
150
200
250
Distance along profile
10
Colorado School of Mines Department of Electrical Engineering and Computer Science
Grayscale Morphology
),(max),(),(
tysxfyxbfbts
11
• Definition of dilation with flat structuring element
• 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)
Colorado School of Mines Department of Electrical Engineering and Computer Science
Grayscale Morphology
),(max),(),(
tysxfyxbfbts
12
• Definition of dilation with flat structuring element
• 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)
Colorado School of Mines Department of Electrical Engineering and Computer Science Colorado School of Mines Department of Electrical Engineering and Computer Science
• Definition of erosion (with flat SE)
• Slide b(s,t) past f(x,y); at each position, take the minimum of f(x,y)
within that window
Gray Scale Erosion
),(min),(),(
tysxfyxbfbts
13
b(s,t)
Colorado School of Mines Department of Electrical Engineering and Computer Science Colorado School of Mines Department of Electrical Engineering and Computer Science
• Definition of erosion (with flat SE)
• Slide b(s,t) past f(x,y); at each position, take the minimum of f(x,y)
within that window
Gray Scale Erosion
),(min),(),(
tysxfyxbfbts
14
b(s,t)
Colorado School of Mines Department of Electrical Engineering and Computer Science 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
θ
θ
f b f b b
f b f b b
• Similar to binary case
– Opening is erosion followed
by dilation
– Closing is dilation followed by
erosion
• 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 16
Colorado School of Mines Department of Electrical Engineering and Computer Science
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
• Open the image with a structuring element,
subtract it from the original
• Leaves only details smaller than the structuring
element
• Matlab example
Top Hat Transform
)( bffh
18
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, []);
Colorado School of Mines Department of Electrical Engineering and Computer Science
Another example
19
• 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 Colorado School of Mines Department of Electrical Engineering and Computer Science
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