Download presentation
Presentation is loading. Please wait.
1
Digital Image Processing
Morphological operation Dr. Ghassabi Tehran shomal University Spring 2015
2
Outline Introduction Digital Image Fundamentals
Intensity Transformations and Spatial Filtering Filtering in the Frequency Domain Image Restoration and Reconstruction Color Image Processing Wavelets and Multi resolution Processing Image Compression Morphological Operation Object representation Object recognition
3
Morphological Image processing
Used to extract image components that are useful in the representation and description of region shape, such as boundaries extraction skeletons convex hull morphological filtering thinning pruning
4
Morphological Image processing
Sets in mathematic morphology represent objects in an image: binary image (0 = white, 1 = black) : the element of the set is the coordinates (x,y) of pixel belong to the object Z2 gray-scaled image : the element of the set is the coordinates (x,y) of pixel belong to the object and the gray levels Z3
5
Morphological Image processing
Operators by examples:
6
Morphological Image processing
Preliminary: A: A set in Z2 with elements of a=(a1,a2)
7
Morphological Image processing
Reflection and Translation by examples: Need for a reference point. Reference point
8
Morphological operations
Erosion Dilation Opening Closing Reconstruction
9
Fundamental Morphological Operators:
Dilation: Set B: A structural elements. Result Relation to Convolution mask: Flipping Overlapping Other names: Grow, Expand
10
Dilation Set A
11
Dilation Output
12
Dilation Output
13
Dilation Output
14
Dilation Output
15
Dilation Result
16
Morphological Image processing
17
Morphological Image processing
Dilation by example: B: a 3×3 mask.
18
Morphological Image processing
Application: Gap filling
19
Dilation in MATLAB I=imread(‘ im.jpg‘); I1=im2bw(I); S=[0 1 0;1 1 1;0 1 0]; I2=imdilate(I1,S); Subplot(1,2,1);imshow(I); Subplot(1,2,2);imshow(I1);
20
Dilation in MATLAB Exercise
What is the result by S=[1 1 1;1 1 1;1 1 1]; What is the result when I1=1-I? Do dilation for a retinal image. Use different structuring elements by “Strel” Se1=strel(‘line’,3,0); Se1=strel(‘line’,3,90); Se1=strel(‘square,3);
21
Morphological Image processing
Erosion: Set B: A structural elements. Other banes: Shrink, Reduce Result در صورتی جواب داریم که تمام المانهای B با A تطابق داشته باشه.
22
Erosion Set A Structuring element
23
Erosion
24
Erosion
25
Erosion
26
Erosion
27
Erosion
28
Erosion Result
29
Erosion Set A Structuring element
30
Erosion
31
Erosion
32
Erosion
33
Erosion
34
Erosion
35
Erosion
36
Erosion Result
37
Erosion in MATLAB I=imread(‘ im.jpg‘); I1=im2bw(I); S=[0 1 0;1 1 1;0 1 0]; I2=imerode(I1,S); Subplot(1,2,1);imshow(I); Subplot(1,2,2);imshow(I1);
38
Erosion in MATLAB Exercise
Se1= Stre1(‘square’,3); Se1= Stre1(‘square’,5); Se1= Stre1(‘square’,7);
40
Morphological Image processing
41
Morphological Image processing
Erosion by example: B: a 3×3 mask.
42
Morphological Image processing
Erosion by example: 11 pixels (Diameter)
43
Morphological Image processing
Erosion (More examples):
44
Morphological Image processing
Dilation-Erosion Duality:
45
Morphological Image processing
Erosion Application: Remove details 1,3,5,7,9, and 15 Erode with 13 Dilate with 13
46
Morphological Image processing
Opening and Closing: Dilation expands and Erosion shrinks. Opening: Smooth contour Break narrow isthmuses (Means:(تنگه Remove thin protrusion Closing: Fuse narrow breaks, and long thin gulfs. Remove small holes, and fill gaps.
47
Morphological Image processing
Opening and Closing: Dilation expands and Erosion shrinks. Opening: A erosion followed by a dilation using the same structuring element for both operations. Closing: A Dilation followed by a erosion using the same structuring element for both operations. Opening برای صاف کردن لبه ها و از بین بردن خطوط باریک closing\ برای smoothing و از بین بردن حفره ها و فاصله های نزدیک
48
Opening Set A Structuring element B
49
Opening Erosion
50
Opening Dilation
51
Morphological Image processing
Opening illustration
52
Morphological Image processing
Opening illustration
53
Morphological Image processing
opening : Separate out the circles from the lines, so that they can be counted. Opening with a disk shaped structuring element 11 pixels in diameter gives
54
Morphological Image processing
opening : Extracting the horizontal and vertical lines. The results of an Opening with a 3×9 vertically and 9x3 horizontally oriented structuring element is shown
55
Closing Set A Structuring element B
56
Closing Dilation
57
Closing Erosion
58
Morphological Image processing
Closing illustration:
59
Morphological Image processing
Closing Illustration:
60
Morphological Image processing
Closing (More examples): Removing the small holes while retaining the large holes Closing with a 22 pixel diameter disk Closing with a disk-shaped structuring element with a diameter larger than the smaller holes
61
Morphological Image processing
Closing (More examples): Enhance binary images of objects obtained from thresholding
62
Opening and Closing:
63
Morphological Image processing
Opening and Closing Duality: Opening Properties: A○B is a subset (subimage) of A If C is a subset of D, then C○B is a subset of D○B (A○B)○B = A○B ↔ Multiple apply has no effect. Closing Properties: A is a subset (subimage) of AB If C is a subset of D, then CB is a subset of DB (AB)B = AB ↔ Multiple apply has no effect.
64
Noise Reduction Opening Dilation of Opening Closing of Opening
65
Opening and Closing in MATLAB Exercise
I=imread(‘ im.jpg‘); I1=im2bw(I); S=strel(‘square’,13); I2=imopen(I1,S); I2=imclose(I2,S); Subplot(1,2,1);imshow(I); Subplot(1,2,2);imshow(I1);
66
Morphological Image processing
Hit-or-Miss Shape Detection X-Y-X shape X enclosed by W B1: Object related B2: Background related For shape recognition
67
Morphological Image processing
Hit-or-Miss: Application: shape recognition
68
Hit-Miss in MATLAB B1=[0 1 0; 1 1 1;0 1 0]; B2=[1 0 1; 0 0 0; 1 0 1];
I2=imerode(I1,B1); I3=imerode((~I1), B2); I4=I2.^I3; I4 are objects that we want to detect
69
Morphological Image processing
Hit-or-Miss: Another application: Corners
70
Morphological Image processing
Morphological Operator Applications: Boundary Extraction: Eroded Difference
71
Boundary Extraction (A) = A – (A B) – Set A B
72
Boundary Extraction A – B (A)
73
Boundary Extraction in MATLAB
I2=imerode(I,B2); I3=I-I2;
74
Morphological Image processing
Region Filling: Start form p inside boundary. مختصات نقطه شروع را باید بدهیم که با structure دایلیت میشه و بعد اشتراک میگیریم با مکمل A آخرش دورش رو هم در نظر گرفته
75
Morphological Image processing
Region Filling Example: Semi-automated to cancel reflection effect Fig. 9.16(c) shows the result of filling all the spheres. Because it must be known whether black points are background points or sphere inner points, fully automating this procedure requires that additional "intelligence" be built into the algorithm. We give a fully automatic approach in Section based on morphological reconstruction. (See also Problem 9.23.)
76
Region Filling in MATLAB
[M,N]=size(I1); M1=[0 1 0; 1 1 1; 0 1 0]; P0=zeros(M,N); P0(126,152)=1; I2=imdilate(P0,M1); I2=I2.*(~I1); done=1; While(done) if (I2==P0) done=0; else P0=I2 end I2=imdilate(I2,M); end I2-=I1+I2; imshow(I2)
77
Region Filling in MATLAB
I2=imfill(I1, [126,152]);
78
Morphological Image processing
Connected components Extraction: Start from p belong to desired region. Image labeling مکان اولین نقطه سفید در عکس نقطه شروع هست.
79
Connected Component - Labeling
Starting point p q Structuring element B Image A
80
Connected Component - Labeling
X0 B X1 = (X0 B) A
81
Connected Component - Labeling
X2 = (X1 B) A X8 = (X7 B) A
82
Connected Components in MATLAB
I1=imread(); I1=im2bw(A); [M,N]=size(I1); I1=uint8(I1).*255; M1=[0 1 0; 1 1 1; 0 1 0]; I1=imopen(I1,M1); P0=zeros(M,N); I2=P0; %find P P=0; While(P==0&& i<M) if (Ij<N) j=j+1; else j=1; i=i+1 end if (I1(i,j)==255) P=1; end end P0(i,j)=255;
83
Connected Components in MATLAB
I2=imdilate(P0,M1); I2=uint8(I2); I2=I2.*(I1); done=1; While(done) if (I2==P0) done=0; else P0=I2 end I2=imdilate(I2,M);I2=I2.*(I1); end [x,y]=find(I2==255); x1=mean(x); Y1=mean(y); S=sum(sum(I2./255)); imshow(I2) This code Finds one of objects
84
Connected Components in MATLAB
I1=imread(); I1=im2bw(A); [M,N]=size(I1); I1=uint8(I1).*255; M1=[0 1 0; 1 1 1; 0 1 0]; I1=imopen(I1,M1); P0=zeros(M,N); I2=P0; P=1; n=1; %find P While (P==1) P=0; While(P==0&& i<M) if (Ij<N) j=j+1; else j=1; i=i+1 end if (I1(i,j)==255) P=1; end end P0(i,j)=255; This code finds other objects
85
Connected Components in MATLAB
I2=imdilate(P0,M1); I2=uint8(I2); I2=I2.*(I1); done=1; While(done) if (I2==P0) done=0; else P0=I2 end I2=imdilate(I2,M);I2=I2.*(I1); end [x,y]=find(I2==255); X1(n)=mean(x); Y1(n)=mean(y); S(n)=sum(sum(I2./255)); I2=(I2./255).*(n); I1=I1-I2 n=n+1; End X1(n-1)=[]; y1(n-1)=[]; imshow(I2) This code finds other objects
86
Connected Components in MATLAB
I=imread(I); I1=im2bw(I); [l,n]=bwlabel(I1) [r,c]=find(l==1) R=mean(r);c=mean(c) n % the number of objects
87
Morphological Image processing
Original Connected Components with size Thr Erosion (5×5)
88
Morphological Image processing
Convex Hull of S: Smallest Convex set H, containing S Define Four basic structural elements, Bi, i=1,2,3,4 Convex
89
Morphological Image processing
Converged: C C C C
90
Morphological Image processing
Shortcoming of previous algorithm: Grow more than minimum required convex size. Limit to vertical-horizontal expansion.
91
Morphological Image processing
Thinning:
92
Morphological Image processing
Convert to m-connection
93
Morphological Image processing
Thickening: Structural elements are as before. where B is a structuring element suitable for thickening. As in thinning. thickening can be defined as a sequential operation: The structuring elements used for thickening have the same form as those shown in Fig. 9.2l(a). but with all 1s and 0s interchanged. However, a separate algorithm for thickening is seldom used in practice. Instead, the usual procedure is to thin the background of the set in question and then complement the result. In other words. to thicken a set A. we form C = AC, thin C, and then form C C. Figure 9.22 illustrates this procedure. Depending on the nature of A. this procedure can result in disconnected points, as Fig. 9.22(d) shows. Hence thickening by this method usually is followed by post processing to remove disconnected points Note from Fig. 9.22(c) that the thinned background forms a boundary for the thickening process This useful feature is not present in the direct implementation of thickening using Eq. (9.5-I0). and it is one of the principal reasons for using background thinning to accomplish thickening.
94
Morphological Image processing
Skeletonization A with notation S(A): For z belong to S(A) and (D)z, the largest disk centered at z and contained in A, one can not find a larger disk containing (D)z and included in A. Disk (D)z touches the boundary of A at two or more different points. Skeletonization is a process for reducing foreground regions in a binary image to a skeletal remnant that largely preserves the extent and connectivity of the original region while throwing away most of the original foreground pixels. How this works: imagine that the foreground regions in the input binary image are made of some uniform slow-burning material. Light fires simultaneously at all points along the boundary of this region and watch the fire move into the interior. At points where the fire traveling from two different boundaries meets itself, the fire will extinguish itself and the points at which this happens form the so called `quench line'. This line is the skeleton.
95
Morphological Image processing
Skeleton by example: As Fig shows. the notion of a skeleton. S(A). of a set A is intuitively simple. We deduce from this figure that (a) lf z is a point of S(A) and (D)z is the largest disk centered at z and contained in A. one cannot find a larger disk (not necessarily centered at z) containing (D)z and included in A. The disk (D)z is called a maximum disk. (b) The disk (D)Z touches the boundary of A at two or more different places.
96
MATLAB bwmorph
97
Morphological Image processing
Skeleton The skeleton/MAT can be produced in two main ways. 1. to use some kind of morphological thinning that successively erodes away pixels from the boundary (while preserving the end points of line segments) until no more thinning is possible, at which point what is left approximates the skeleton. 2. to calculate the distance transform of the image. The skeleton then lies along the singularities (i.e. creases or curvature discontinuities) in the distance transform.
98
Morphological Image processing
Application: Simplify a shape by pruning its skeleton:
99
Morphological Image processing
Formulation:
100
Morphological Image processing
101
Morphological Image processing
Another way to find skeleton: calculate the distance transform of the image. The skeleton then lies along the singularities (i.e. creases or curvature discontinuities) in the distance transform. Note that we are using the `chessboard' distance metric. The distance transform is an operator normally only applied to binary images. The result of the transform is a graylevel image that looks similar to the input image, except that the graylevel intensities of points inside foreground regions are changed to show the distance to the closest boundary from each point. The distance transform of a simple shape
102
Morphological Image processing
103
Morphological Image processing
Pruning
104
Morphological Image processing
Iteratively prune an image:
105
Morphological Image processing
Solve a maze puzzle by thinning all paths and pruning dead ends:
106
Morphological Image processing
Morphological Reconstruction
107
Reconstruction in MATLAB
B1=ones(51,1); I2=imerode(I1, B1); I3=imreconstruct(I2,I1);
108
Morphological Image processing
109
Morphological Image processing
110
Morphological Image processing
111
Morphological Image processing
Morphological reconstruction has a broad spectrum of practical applications, each determined by the selection of the marker and mask images, by the structuring elements used, and by combinations of the primitive operations defined .in the preceding discussion. The following examples illustrate the usefulness of these concepts. Opening by reconstruction: In a morphological opening, erosion removes small objects and the subsequent dilation attempts to restore the shape of objects that remain. However, the accuracy of this restoration is highly dependent on the similarity of the shapes of the objects and the structuring element used.
112
Morphological Image processing
Opening by reconstruction restores exactly the shapes of the objects that remain after erosion. The opening by reconstruction of size n of an image F is defined as the reconstruction by dilation of F from the erosion of size n of F; that is, where (F nB) indicates n erosions of F by B Note that F is used as the mask in this application.
113
Morphological Image processing
Figure 9.29 shows an example of opening by reconstruction. In this illustration, we are interested in extracting from Fig. 9.29(a) the characters that contain long. vertical strokes. Opening by reconstruction requires at least one erosion. so we perform that step first. Figure 9.29(b) shows the erosion of Fig. 9.29(a) with a structuring element of length proportional to the average height of the tall characters (51 pixels) and width of one pixel.
114
Morphological Image processing
115
Morphological Image processing
Figure 9.31 shows a more practical example. Figure 9.31(b) shows the complement of the text image in Fig. 9.31(a), and Fig. 9.31(c) is the marker image, F, generated using Eq. (9.5-28).This image has a border of 1s, except at locations corresponding to 1s in the border of the original image. Finally, Fig (d) shows the image with all the holes filled.
116
Morphological Image processing
Border clearing: A border-clearing procedure based on morphological reconstruction: original image as the mask and the following marker image: first computes the morphological reconstruction (F) (which simply extracts the objects touching the border) and then computes the difference to obtain an image, X, with no objects touching the border The extraction of objects from an image for subsequent shape analysis is a fundamental task in automated image processing An algorithm for removing objects that touch (i.e., are connected to) the border is a useful tool because (1) it can be used to screen images so that only complete objects remain for further processing, or (2) it can be used as a signal that partial objects are present in the field of view.
117
Morphological Image processing
118
Morphological Image processing
As an example, consider the text image again. Figure 9.32(a) in the previous page shows the reconstruction (F) obtained using a 3 3 structuring element of all 1s (note the objects touching the boundary on the right side), and Pig. 9.32(b) shows image X, computed using Eq. (9.5-31). If the task at hand were automated character recognition. having an image in which no characters touch the border is most useful because the problem of having to recognize partial characters (a difficult task at best) is avoided
119
Morphological Image processing
Extension to Gray-Level images: f(x,y): the input image b(x,y): a structuring element (a subimage function) (x,y) are integers. f and b are functions that assign a gray-level value (real number or real integer) to each distinct pair of coordinate (x,y)
120
Morphological Image processing
Extension to Gray-Level images: Dilation: Df and Db are the domains of f and b, respectively. condition (s-x) and (t-y) have to be in the domain of f and (x,y) have to be in the domain of b is similar to the condition in binary morphological dilation where the two sets have to overlap by at least one element
121
Gray-Scale Morphology
5 100 102 110 103 109 10 12 14 11 17 112 13 101 106 105 104 15 111 100 102 110 103 109 115 117 17 108 13 10 111 12 114 11 14 107 116 101 20 15 112 104 Structuring element b تصویر روشن تر می شود Image f Dilated image
122
Gray-Scale Morphology
5 100 102 110 103 109 10 12 14 11 17 112 13 101 106 105 104 15 111 100 102 110 103 109 5 7 6 17 13 10 95 12 11 14 101 15 112 104 Structuring element b تصویر تاریک می شود Image f Eroded image
123
Morphological Image processing
Dilation Similarity with Convolution: f(s-x) : f(-x) is simply f(x) mirrored with respect to the original of the x axis. the function f(s-x) moves to the right for positive s, and to the left for negative s. Max operation replaces the sums of convolution Addition operation replaces with the products of convolution. General effect If all the values of the structuring element are positive, the output image tends to be brighter than the input Dark details either are reduced or eliminated, depending on how their values and shapes relate to the structuring element used for dilation.
124
Morphological Image processing
1D example:
125
Morphological Image processing
Erosion: Condition (s+x) and (t+y) have to be in the domain of f and (x,y) have to be in the domain of b is similar to the condition in binary morphological erosion where the structuring element has to be completely contained by the set being eroded.
126
Morphological Image processing
Similarity to 2D correlation f(s+x) moves to the left for positive s and to the right for negative s. General effect If all the elements of the structuring element are positive, the output image tends to be darker than the input The effect of bright details in the input image that are smaller in area than the structuring element is reduced, with the degree of reduction being determined by the gray-level values surrounding the bright detail and by the shape and amplitude values of the structuring element itself.
127
Morphological Image processing
1D case:
128
Morphological Image processing
Erosion-Dilation Duality:
129
Morphological Image processing
Structuring elements in gray-scale morphology: Non flat Flat
130
Morphological Image processing
131
Morphological Image processing
Dilation-Erosion Original Dilation Erosion
132
Morphological Image processing
Erosion and Dilation Morphological Image processing Application of dilation: Removing noise
133
Morphological Image processing
Erosion and Dilation Morphological Image processing Dilation in edge detection:
134
Morphological Image processing
Erosion and Dilation Morphological Image processing Erosion in removing salt noise:
135
Morphological Image processing
Opening-Closing: Same (binary) relation with Dilation-Erosion: هر دو تصویر را smooth میکنند.
136
Morphological Image processing
1D Example: One scan line Rolling ball for opening Opening results Rolling ball for Closing Closing Results
137
Morphological Image processing
Opening-Closing Properties: Opening: Closing: er indicates that the domain of e is a subset of the domain of r, and also that e(x,y) ≤ r(x,y) for any (x,y) in the domain of e
138
Morphological Image processing
Opening The structuring element is rolled underside the surface of f All the peaks that are narrow with respect to the diameter of the structuring element will be reduced in amplitude and sharpness So, opening is used to remove small light details, while leaving the overall gray levels and larger bright features relatively undisturbed. The initial erosion removes the details, but it also darkens the image. The subsequent dilation again increases the overall intensity of the image without reintroducing the details totally removed by erosion.
139
Morphological Image processing
Closing The structuring element is rolled on top of the surface of f Peaks essentially are left in their original form (assume that their separation at the narrowest points exceeds the diameter of the structuring element) So, closing is used to remove small dark details, while leaving bright features relatively undisturbed. The initial dilation removes the dark details and brightens the image The subsequent erosion darkens the image without reintroducing the details totally removed by dilation
140
Morphological Image processing
Opening Closing Example Opening: Decreased size of small bright details. No changes to dark region Closing: Decreased size of small dark details. No changes to bright region
141
Morphological Image processing
142
Morphological Image processing
Erosion Opening Opening:suppresses bright details smaller than the specified SE and closing suppresses dark details. They are used often in combination as morphological filters for image smoothing and noise removal
143
Morphological Image processing
Opening in removing salt noise:
144
Morphological Image processing
Opening in removing pepper noise:
145
Morphological Image processing
Closing for pepper noise:
146
Morphological Image processing
Closing for salt noise:
147
Morphological Image processing
Gray Level Morphological Examples: Smoothing: Gradient: Laplacian: Dilation Erosion Smoothing Gradient Laplacian Dilation and erosion can be used in combination with image subtraction to obtain the morphological gradient of an image: The dilation thickens regions in an image and the erosion shrinks them. Their difference emphasizes the boundaries between regions.
149
Morphological Image processing
Smoothing
150
Morphological Image processing
Gradient:
151
Gradient and smoothing in MATLAB
I=imread(); I=rgb2gray(I); M=strel([5 5 5; 5 5 5; 5 5 5]); I1=imdilate(I,M); I2=imerode(I,M) I3=imopen (I,M) I4=imclose(I,M); I5=imclose(I3,M) %smoothing I6=imclose(I3,M);
152
Morphological Image processing
Combining image subtraction with openings and closings results in top-hat and bottom-hat transformations. Top-hat transformation: Bottom-hat transformation: Notice: The top-hat transform is used for light objects on a dark background, and the bottom-hat transform is used for the converse.
154
Morphological Image processing
Top-hat: Enhancing details in presence of shades
155
Morphological Image processing
Granulometry Determining the size distribution of particles in an image. Granulometry consists of applying openings with SEs of increasing size. For each opening, the sum of the pixel values in the opening is computed. To emphasize changes between successive openings, we compute the difference between adjacent elements of the 1-D array. The peaks in the plot are an indication of the size distributions of the particles in the image.
156
Morphological Image processing
Granulometry
157
Morphological Image processing
Texture Segmentation
158
Morphological Image processing
Finding a boundary between two regions based on their textural content.
159
Morphological Image processing
Gray-scale Morphological reconstruction: Let f and g denote the marker and mask images. Geodesic dilation of size 1: ^ denotes the point-wise minimum operator. Geodesic dilation of size n: Geodesic erosion of size 1: Geodesic erosion of size n:
160
Morphological Image processing
Gray-scale Morphological reconstruction: Morphological reconstruction by dilation: Morphological reconstruction by erosion:
161
Morphological Image processing
Gray-scale Morphological reconstruction: Opening by reconstruction of size n: Closing by reconstruction of size n:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.