I2200: Digital Image processing Lecture 7: Morphological Image Processing Prof. YingLi Tian Oct. 25, 2017 Department of Electrical Engineering The City College of New York The City University of New York (CUNY) Thanks to G&W website and Dr. Shahram Ebadollahi for slide materials 1
Outline What is Mathematical Morphology? Background Notions Introduction to Set Operations on Images Basic operation Erosion, Dilation, Opening, Closing, Hit-or-Miss Applications Boundary detection, skeleton, Morphological operations on gray-level images
What is Mathematical Morphology? An (imprecise) Mathematical Answer A mathematical tool for investigating geometric structure in binary and grayscale images. Shape Processing and Analysis Visual perception requires transformation of images so as to make explicit particular shape information. Goal: Distinguish meaningful shape information from irrelevant one. The vast majority of shape processing and analysis techniques are based on designing a shape operator which satisfies desirable properties. 3
Morphological Image Processing Started in 1960s by G. Matheron and J. Serra Analysis of form and structure of objects Tools/Operations for describing/characterizing image regions and image filtering Images are treated as sets 4
Morphological Image Processing 5
Applications - filtering 6
Applications segmentation 1 7
Applications segmentation 2 8
Applications - quantification 9
Background Notions: Image as a Set 10
Set Operations on Images 11
Set Operations on Images 12
Set Operations on Images - Union & Intersection 13
Set Operations on Images Matlab functions 14
Set Operations on Images 15
Morphological Image Operations All morphological image operations are the result of interaction between a set representing an image and a set representing a structuring element All interactions are based on combination of intersection, union, complementation and translation 16
Graphs 17
Grids & Connectivity 18
Structuring Element (SE): A Small Set for Probing Images 19
Morphological Image Processing Erosions and dilations are the most elementary operators of mathematical morphology. More complicated morphological operators can be designed by means of combining erosions and dilations. 20
Erosion Set of all points z such that B, translated by z, is included in A Effect of erosion using a 3 3 square structuring element 21
Erosion 22
Erosion: implementation Suppose that the structuring element is a 3 3 square. 1 1 1 1 1 1 1 1 1 Structuring element Note that in subsequent diagrams, foreground pixels are represented by 1's and background pixels by 0's. The structuring element is now superimposed over each foreground pixel ( input pixel ) in the image. If all the pixels below the structuring element are foreground pixels then the input pixel retains it s value. But if any of the pixels is a background pixel then the input pixel gets the background pixel value. 23
Erosion Example 24
Dilation Set of all points z such that B, flipped and translated by z, has a non-empty intersection with A B = structuring element NOTE:the flipping of the structuring element is included in analogy to convolution. Not all Authors perform it. 25
Dilation 26
Dilation Effect of dilation using a 3 3 square structuring element 27
Dilation: Examples bridging the gaps 28
Erosion and Dilation Example eliminating small objects NOTE: white objects on black background (opposite wrt prev. slides) NOTE: the final dilation will NOT yield in general the exact shape of the original objects 29
clear all; B=zeros(256,256); % create 256x256 image for i=128:160 for j=128:160 B(i,j)=1; end end for i=20:25 for j=30:190 B(i,j)=1; end end i=1; while i<40 % generate 40 random pixels x=uint8(rand*255); y=uint8(rand*255); B(x,y)=1;i=i+1; end imshow(b); title('original image'); K3=ones(3); K5=ones(5); K7=ones(7); K9=ones(9); % create kernels B3=imdilate(B,K3); B5=imdilate(B,K5); % apply dilation B7=imdilate(B,K7); B9=imdilate(B,K9); figure; imshow(b3); title('dilated image with 3 by 3'); figure; imshow(b5); title('dilated image with 5 by 5'); figure; imshow(b7); title('dilated image with 7 by 7'); figure, imshow(b9); title('dilated image with 9 by 9');
Properties of Erosion and Dilation 31
Opening and Closing Opening and Closing are morphological operations which are based on dilation and erosion. Opening smoothes the contours of objects, breaks narrow isthmuses and eliminates thin protrusions. Closing also produces the smoothing of sections of contours but fuses narrow breaks, fills gaps in the contour and eliminates small holes. Opening is basically erosion followed by dilation while closing is dilation followed by erosion.
Opening and closing OPENING is erosion followed by dilation CLOSING is dilation followed by erosion 33
Opening An opening is defined as an erosion followed by a dilation using the same structuring element for both operations. Effect of opening using a 3 3 square structuring element
Opening 35
Closing Effect of closing using a 3 3 square structuring element 36
Closing 37
Property A property: Erosion and Dilation Opening and Closing are dual operators wrt set complementation and reflection: ( A ( A B) B) C C A A C C Bˆ Bˆ 38
Opening and Closing: Example 39
Opening and Closing: Example Gaps exist in the output; Better results with a smaller SE 40
Hit-or-Miss Transformation The hit-and-miss transform is a general binary morphological operation that can be used to look for particular patterns of foreground and background pixels in an image. The hit-and-miss transform is a basic tool for shape detection. Concept: To detect a shape: --Hit object --Miss background
Hit-or-Miss Transformation The structural elements used for Hit-or-miss transforms are an extension to the ones used with dilation, erosion etc. The structural elements can contain both foreground and background pixels, rather than just foreground pixels, i.e. both ones and zeros. The structuring element is superimposed over each pixel in the input image, and if an exact match is found between the foreground and background pixels in the structuring element and the image, the input pixel lying below the origin of the structuring element is set to the foreground pixel value. If it does not match, the input pixel is replaced by the boundary pixel value. A B ( A B ) ( A B ) C 1 2
Hit-or-Miss Transformation Four structuring elements used for corner finding in binary images using the hit-and-miss transform. Note that they are really all the same element, but rotated by different amounts. Matlab Command : bwhitmiss
Hit-or-Miss Transformation 44
Hit-or- Miss Transfor mation 45
Boundary Extraction The boundary of a set X is obtained by first eroding X by structuring element K and then taking the set difference of X and it s erosion. The resultant image after subtracting the eroded image from the original image has the boundary of the objects extracted. The thickness of the boundary depends on the size of the structuring element.
Boundary Extraction 47
Boundary Extraction Example 48
Region filling X while X X 0 F P X k X k k X X ( k 1 A k 1 do B) A C The dilation would fill the whole area were it not for the intersection with AC Conditional dilation 49
Hole Filling Example 50
Connected component extraction 51
Connected component extraction 52
Thinning 53
Thickening 54
Skeletons Maximum disk: largest disk included in A, touching the boundary of A at two or more different places 55
Skeletons Define : A kb ((( A B) B)... B) K 56
Skeletons It is not granted that the resulting skeleton is maximally thin, connected, minimally eroded. Other techniques exist; e.g., the Medial Axis Transform, or conditional thinning algorithms. 57
Bwmorph Matlab command: options 58
Matlab examples - dilation 59
Matlab examples - erosion 60
Matlab examples - closing 61
Matlab examples - opening 62
Matlab examples - HMT 63
Basic Elements 64
Properties of morphological operations 65
Properties of morpholo gical operations 66
Properties of morpholo gical operations 67
Announcement HW3 is out today, due on 10/31. Keshan will present HW3 on 11/01. Read Chapter 9 Final project: Send me the following info today The project title and a short description if you choose your own project (must be image processing related). Your partner if you want to team with someone. 68