Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Morphological Image Processing


Published on

A report on Morphological Image Processing presented by Sarjana Singh , a student of SOE, CUSAT (2007-2011 batch)

Morphology is a theory and technique for the analysis and processing of geometrical
structures, based on set theory and random functions. Morphology is most commonly
applied to digital images, but it can be employed as well on graphs, meshes, solids,
and many other spatial structures. Morphology was originally developed for binary
images, and was later extended to grayscale functions and images. The purpose of
morphological processing is primarily to remove imperfections added during segmentation.
The basic operations are erosion and dilation .Using the basic operations we can perform
opening and closing More advanced morphological operation can then be implemented
using combination of all of these.

Published in: Technology, Art & Photos

Morphological Image Processing

  2. 2. Division of Computer Engineering School of Engineering Cochin University of Science & Technology Kochi-682022_________________________________________________________ CERTIFICATE Certified that this is a bonafied record of the seminar titled MORPHOLOGICAL IMAGE PROCESSING Done By Sarjana Singhof VII semester Computer Science & Engineering in the year 2010 in partialfulfillment of the requirements for the award of Degree of Bachelor of Technologyin Computer Science & Engineering of Cochin University of Science & TechnologyDr.David Peter S Mrs Sheena SHead of the Division Seminar Guide
  3. 3. ACKNOWLEDGEMENTI am greatly indebted to Dr. David Peter, Head of Department, Division of ComputerScience, CUSAT for permitting me to undertake this work.I express my heartfelt gratitude to my respected Seminar guide Mrs Sheena S for herkind and inspiring advise which helped me to understand the subject and its semanticsignificance.I am extremely thankful to our seminar coordinator Mr. Sudheep Elayidom M for hisvaluable suggestions for presentation issue .I am also very thankful to my colleagues who helped and co-operated with me in conductingthe seminar by their active participation.
  4. 4. ABSTRACT MORPHOLOGICAL IMAGE PROCESSINGMorphology is a theory and technique for the analysis and processing of geometricalstructures, based on set theory and random functions. Morphology is most commonlyapplied to digital images, but it can be employed as well on graphs, meshes, solids,and many other spatial structures. Morphology was originally developed for binaryimages, and was later extended to grayscale functions and images. The purpose ofmorphological processing is primarily to remove imperfections added during segmentation.The basic operations are erosion and dilation .Using the basic operations we can performopening and closingMore advanced morphological operation can then be implementedusing combinations of all of these.
  5. 5. LIST OF FIGURESFigure 2.1. Dialtion process 7Figure 2.2 Morphological dialation of binary image 8Figure 2.3 Erosion process. 9Figure 2.5 Erosion eliminating irrelevant details 10Figure2,6 Opening process 11Figure 2.7 Closing process . 12Figure 2.8 Noise filtering 12Figure 3.1: Region filling 18Figure 3.2: Morphological smoothing 19Figure 3.3 Morphological gradient 22Figure 3.4 Granulomerety 24-25Figure 3.4 Textural segmentation 27
  8. 8. MORPHOLOGICAL IMAGE PROCESSING CHAPTER 1 INTRODUCTION1.1 PurposeMorphology is a theory and technique for the analysis and processing of geometricalstructures, based on set theory and random functions. Morphology is most commonlyapplied to digital images, but it can be employed as well on graphs, meshes, solids, andmany other spatial structures.Morphology was originally developed for binary images, and was later extendedto grayscale functions and images. The subsequent generalization to complete lattices iswidely accepted today as Morphology’s theoretical foundation.1.2 Scope Morphology is a broad set of image processing operations that process imagesbased on shapes. Morphological operations apply a structuring element to an input image,creating an output image of the same size. In a morphological operation, the value ofeach pixel in the output image is based on a comparison of the corresponding pixel in theinput image with its neighbors. By choosing the size and shape of the neighborhood, youcan construct a morphological operation that is sensitive to specific shapes in the inputimage.The most basic morphological operations are dilation and erosion. Dilation adds pixels tothe boundaries of objects in an image, while erosion removes pixels on object boundaries.The number of pixels added or removed from the objects in an image depends on the sizeand shape of the structuring element used to process the image. In the morphologicaldilation and erosion operations, the state of any given pixel in the output image isdetermined by applying a rule to the corresponding pixel and its neighbors in the inputDivision of Computer Engineering, SOE 1
  9. 9. MORPHOLOGICAL IMAGE PROCESSINGimage. The rule used to process the pixels defines the operation as dilation or an erosion.This table lists the rules for both dilation and erosion.1.3Overall descriptionMorphology is set of fundamental operations on binary images (2-D sets of booleanvalues). It is a very simple, nonlinear convolution-like operation between two such sets.Unlike linear convolution, morphology takes the Min and Max of elements in the set.One set is the image per se; the other is the kernel of the convolution, which is calleda structuring element and has a defined origin (sometimes called the "center"). Binarymorphology is extremely important for fast, low-level image matching operations --every commercial "machine vision" system has it because of its usefulness. Back in theperiod around 1990, if you wanted to do fast pattern matching, you could buy such asystem from any one of several firms (see below). These implemented binarymorphological operations on custom systems with wide registers at about 1 billion pixeloperations/second. Today, using the destination word accumulation method(implemented in Leptonica) on a 1 GHz CPU, you can do binary morphology up to anorder of magnitude faster! So if you need fast matching operations on binary images, readon. And if you are doing image analysis on grayscale or color images, binary morphologycan often be used to give quick and spatially detailed "answers" to questions of interest.Division of Computer Engineering, SOE 2
  10. 10. MORPHOLOGICAL IMAGE PROCESSING CHAPTER 02 BASIC THEORY BEHIND MIP2.1. Binary MorphologyBinary morphology is about operations on sets. The sets are ON (black) pixels in a 2-dimensional image. As with all image processing operations, there is a source image thatis operated on to produce adestination image. In the following, we use one set ofconventions to describe the erosion and dilation operations as set operations. Otherconventions exist, and you should keep this in mind when you read the literature.The basic binary morphology operations are dilation and erosion . In a binary image, werefer to the foreground (black) pixels variously as "black", "foreground", "ON" or "1".We refer to the background (white) pixels variously as "white", "background", "OFF" or"0". Loosely speaking, dilation "smears" the foreground and erosion "thins" theforeground. These two operations are actually dual in that an erosion of the foreground isequivalent to a dilation of the background. Dilation can be implemented as follows: startwith a cleared destination image (all OFF pixels). Then do a sequence of logical ORoperations of the source image with the destination, each time with a specific shift, asdetermined by a pattern called a structuring element (Sel). The Sel is a 2-dimensionalpattern of hits, all relative to an origin that is often referred to as the center of the Sel. It isa set as well. So there are really two sets involved in a morphological operation: theimage and a Sel. For example, consider a Sel that is a horizontal pattern of 5contiguous hits (x,y) = {(-2,0), (-1,0), (0,0), (1,0) and (2,0)}, with an origin at (0,0). Thena dilation of the image by this Sel involves initializing all dest pixels to OFF and thenORing the source five times with source shifts given by the five hits in the Sel.An erosion can be implemented in a similar way. For example, you can initialize all destpixels to ON and then do a set of logical ANDs between the dest and the shifted source.But there is one important difference: you take the shift to be from the hit toDivision of Computer Engineering, SOE 3
  11. 11. MORPHOLOGICAL IMAGE PROCESSINGthe Sel origin, rather than from the origin to the hit. You can think of the Sel as a set ofvectors in two dimensions, and for erosion, you use an inversion of these vectors.Because of the AND, you end up with ON pixels in the destination only where the hits ofthe Sel can all fit on the ON pixels of the source image. In fact, the erosion can beimplemented by placing the Sel with its origin at every ON pixel in the source image and,for every location where all hits in the Sel are placed on ON pixels in the image, an ONpixel is produced in the destination at the location of the Sel origin. Thus, the erosion isa pattern matching operation. The inversion of the Sel for erosion is required to make theerosion a dual of the dilation. The prescription for erosion just given is oversimplified;see the discussion in the next section on boundary conditions.The inversion of the Sel for erosion is also required to make the opening, which is asequence of erosion followed by dilation, both using the same Sel, have the propertycalled idempotence. This means that if you do a second opening, there is no change afterthe first one. Operations that are idempotent have a special significance. The opening canbe visualized as follows: it gives you only those ON pixels where the Sel is able to fitentirely in the foreground. (The erosion gave on pixels only at the Sel origin location ofsuch a pattern match. Then by dilating those pixels, with the same Sel, you get all thepixels in the match.) So the opening projects out a subset of pixels of the source image,and a second opening gives the same result because the Sel fits in those pixels byconstruction. The closing, which is a dilation followed by an erosion with the same Sel, isalso idempotent. It is the dual to the opening, because you can do a closing by openingthe background. Regardless of the convention that is used to define erosion and dilation,the opening and closing operations have a unique definition. All four morphologicaloperations have two important properties: 1. Translational invariance. The operation commutes with translation: if you translate the source and perform an operation, you get the same result as if you performed the operation first and then translated the result. 2. Increasing. If you have two images, one of which has a foreground that is entirely contained in the other, then the results of a morphological operation retain the same order of inclusion.Division of Computer Engineering, SOE 4
  12. 12. MORPHOLOGICAL IMAGE PROCESSING2.1. Boundary ConditionWhy have an entire section on boundary conditions? Why not simply adopt amathematically elegant definition, and use it. For natural images, where there is no apriori bias toward any particular grayscale value for pixels beyond the image proper, thisis a perfectly reasonable approach. For document images, however, this can giveunexpected results.What is the mathematically elegant definition? It is the one that treats erosion and dilationas duals, even in the presence of boundaries. We will call it the symmetric boundarycondition (SBC): extend an image by the min value (0 for binary images) for dilation andby the max value (1 for binary images) for erosion. This gives strict duality. To avoidconfusion, we call the extra pixels that are used to extend the image beyond its actualboundaries the frame pixels.However, for document images, there is a natural bias toward extending the image withbackground (0, OFF) pixels, for both dilation and erosion, because we typically havebackground pixels at the boundaries. So we might want to handle the boundaryconditions by requiring that we get the same result as if the image were actually extendedsufficiently by 0 pixels, for all morphological operations. This does not give strict dualitybetween dilation and erosion, but I find it preferable for document imaging applications.We will call this the asymmetric boundary condition (ABC).Erosion is thus different for SBC and ABC. Suppose you have a binary image with allpixels ON. An erosion with a 3x3 Sel flips a 1 pixel wide border around the image toOFF using ABC, and has no effect on the image using SBC.The most problematic operation on document images is closing. Consider a documentimaging application with binary images, and lets take a specific closing example.Suppose you have an image with one ON pixel, located near the left hand edge at(x=5,y=50), in an image of size 100 x 100, and you dilate with a horizontal structuringelement of width 21 pixels with the origin at its center. Here are the three cases:Division of Computer Engineering, SOE 5
  13. 13. MORPHOLOGICAL IMAGE PROCESSING 1. Closing using asymmetric boundary condition convention with no added border pixels. The dilation stops at the image boundary, and you get a line only 16 ON pixels long (5 to the boundary, the original pixel, and 10 to the right of the original pixel). The subsequent erosion with a 21 pixel wide Sel removes it entirely, because there is no location in which all 21 pixels of the Sel are covered by ON pixels. Removal of the original pixel is not typically what you want for a closing operation. 2. Closing using asymmetric b.c. with added OFF border pixels. The dilation expands the orignal pixel into a line of length 21 that includes 5 frame pixels, and the subsequent erosion leaves a single pixel, the same one that you started with. 3. Closing using a symmetric b.c.. As we will see, this can be implemented without any actual frame pixels being added. But for visualization purposes, imagine there is a frame of OFF pixels for the dilation, which expands the original pixel into a line 21 pixels long, including 5 in the frame. Then change the frame pixels to ON and perform the erosion. Because there are now an infinite number of ON pixels in the frame, the erosion only removes the 10 pixels to the right of the original pixel. The original pixel and the five pixels to its left remain ON. (Remember, the erosion leaves the Sel origin ON if all hits in the Sel are covered by ON pixels.)So we get three different results! The third result, where pixels can be connected with theboundary by the closing, is the mathematically correct one in terms of strict duality(SBC), but for document images, does one really want the closing operation to close gapsfrom image pixels to the boundary? The first result loses the original pixel, which is alsolikely to be undesirable. Only the second result gives us an image that seems intuitivelycorrect for a situation where the image seems naturally to be extended by OFF pixelsbecause the foreground pixels are assumed to be localized to the actual image (without aframe). Note that the second result is independent of the location of the actual imageboundary. This is the reason that were considering boundary conditions in some detail: Iprefer ABC for document images.Division of Computer Engineering, SOE 6
  14. 14. MORPHOLOGICAL IMAGE PROCESSING2.2 Morphological operations1.Dialation:Dilation adds pixels to the boundaries of objects in an image. The value of the outputpixel is the maximum value of all the pixels in the input pixels neighborhood.The dilation of A by the structuring element B is defined by:Example application: Assume we have received a fax of a dark photocopy. Everythinglooks like it was written with a pen that is bleeding. Erosion process will allow thickerlines to get skinny and detect the hole inside the letter "o".Fig:2.1The erosion of the dark-blue square by a disk, resulting in the light-blue square.The following figure illustrates the dilation of a binary image. Note how the structuringelement defines the neighborhood of the pixel of interest, which is circled.(See Understanding Structuring Elements for more information.) The dilation functionapplies the appropriate rule to the pixels in the neighborhood and assigns a value to thecorresponding pixel in the output image. In the figure, the morphological dilationDivision of Computer Engineering, SOE 7
  15. 15. MORPHOLOGICAL IMAGE PROCESSINGfunction sets the value of the output pixel to 1 because one of the elements in theneighborhood defined by the structuring element is on.Morphological Dilation of a Binary ImageFig:2.22.ErosionThe value of the output pixel is the minimum value of all the pixels in the input pixelsneighborhood. In a binary image, if any of the pixels is set to 0, the output pixel is set to0.The erosion of the binary image A by the structuring element B is defined by:Example application: Dilation is the opposite of the erosion. Figures that are very lightlydrawn get thick when "dilated". Easiest way to describe it is to imagine the same fax/textis written with a thicker pen.Division of Computer Engineering, SOE 8
  16. 16. MORPHOLOGICAL IMAGE PROCESSINGFig:2.3The dilation of the dark-blue square by a disk, resulting in the light-blue square withrounded corners.Dilation: Joining broken segmentsOne immediate advantage of the morphological approach over lowpass filtering is thatthe morphological method resulted directly in a binary image, while lowpass filteringstarted with producing gray-scale image.Division of Computer Engineering, SOE 9
  17. 17. MORPHOLOGICAL IMAGE PROCESSINGFig:2.4Erosion & Dilation: eliminating irrelevant detailSuppose we want to eliminate all the squares except largest one. We can do this byeroding the image with a structuring element of a size somewhat smaller thanthe objects we wish to keep. After that, we can restore it by dilating them with the samestructuring element we used for erosion.Fig:2.53.OpeningOpening generally smoothes the contour object,breaks narrow isthmuses, and eliminatesthin protrusions. Opening decreases sizes of the small bright detail, with no appreciableeffect on the darker gray levels, while the closing decreases sizes of the small darkdetails, with relatively little effect on bright features.Opening generally smoothes the contour object, breaks narrow isthmuses, and eliminatesthin protrusions.Division of Computer Engineering, SOE 10
  18. 18. MORPHOLOGICAL IMAGE PROCESSINGThe opening of A by B is obtained by the erosion of A by B, followed by dilation of theresulting image by B:Fig:2.6The opening of the dark-blue square by a disk, resulting in the light-blue square withround corners.3.ClosingClosing also tends to smooth sections of contours but, ass opposed to opening, itgenerally fuses narrow breaks and long thin gulfs, eliminates small holes, and fills gaps inthe contour.Closing also tends to smooth sections of contoursDivision of Computer Engineering, SOE 11
  19. 19. MORPHOLOGICAL IMAGE PROCESSINGFig:2.7The closing of the dark-blue shape (union of two squares) by a disk, resulting in theunion of the dark-blue shape and the light-blue areas.Opening & Closing: Noise FilterThe light elements are completely eliminated in first erosion stage, but unfortunatelyimage is smaller so we have to restore it with dilation (erosion then dilation →opening ofA by B). However, new gaps were created. To counter this effect we have to performclosing on an image again.Fig:2.8Division of Computer Engineering, SOE 12
  20. 20. MORPHOLOGICAL IMAGE PROCESSINGOpening: the intensity of all bright features decreased,depending on the sizes of featurescompared to the SE.unlike the erosion, opening has negligible effect on the dark features,and the effect on the background is negligible.Closing: attenuated dark features, unaffected background.Fig:2.92.4 Properties of Opening and ClosingDualityClosing is the dual of opening:(A ◦ B)c = Ac • ˘BJust as erosion can be implemented using dilation (and vice versa), opening can beimplemented using closing (and vice versa)IdempotenceAn important property of opening and closing operations is that they are idempotent: ifyou apply one more than once,nothing changes after the first application. So,A◦B◦B=A◦BandA•B•B=A•BDivision of Computer Engineering, SOE 13
  21. 21. MORPHOLOGICAL IMAGE PROCESSING2.5Applications of Opening and ClosingOpening and closing are the basic workhorses of morphological noise removal. Openingremoves small objects, and closing removes small holes.Finding ThingsYou can also use opening and closing to find specific shapes in an image. While thesemay not be ―noise‖, theymay just be other things that you don’t care about. (In this sense, perhaps noise is justthings you don’t care about?)Opening can be used to only find things into which a specific structuring element can fit.Subdivision into PartsYou can also extend this idea to part subdivision. Suppose that you know that a particularobject has specific partswith specific shapes. Openings can be used to separate those parts by shaping thestructuring elements to ―fit‖ intothose parts. They don’t have to exactly match the parts—it’s sufficient to only fit intosome parts while not fitting intoothers.2.5Hit-and-MissWhen eroding, the ―0‖s in the structuring element act like ―don’t care‖ conditions—theydon’t really require that the image be on or off at that point, only that the remaining ―1‖pixels fit inside the object. In other words, it finds places that ―look like this‖ (for the 1s),but has no way to say ―but doesn’t look like this‖ (for the 0s). We can can combineerosion and dilation to produce an operator that acts like this: the ―hit and miss‖ operator.The operator takes two elements: one that must ―hit‖ and one that must ―miss‖. Theoperator is defined as follows. If the structuring elements J (hit) and K (miss) are appliedto the image A: A ⊗ (J,K) = (A _ J) ∩ (Ac _ K)Division of Computer Engineering, SOE 14
  22. 22. MORPHOLOGICAL IMAGE PROCESSINGIn other words, the structuring element J must fit inside the object and the element Kmust fit outside the object at that position.This gives us a form of binary template matching. For example, the following structuringelements give an ―upper right‖ corner detector:000110010011001000JKThe J element finds the points with connected left and lower neighbors, and the Helement finds the points without upper, upper right, and right neighbors. In some cases,we’ll simply use a single structuring element B, with the assumption that J = B andK = Bc. I.e., A ⊗ B = A ⊗ (B,Bc) = (AB) ∩ (Ac _ Bc)Notice that this doesn’t, however, allow for a third case: ―don’t care‖ pixels—ones thatcould be either inside or outside the shape. Some authors will for this reason write thetwo operators as a single one using 1s for the hits, 0s for the misses, and ―x‖s for thedon’t-care positions. In the previous example, this would be written asx00110x1xThis form is perhaps more useful for visualizing what the structuring element is designedto find. Remember, though, that you still have to apply two different operators, one forhit (the 1s) and one for miss (the 0s), when implementing hit-and-miss.EXAMPLEFingerprint is skeletonized. A disadvantage of this particular skeletonization algorithm isthat it leaves a considerable amount of fuzz, short As additional examples of binary imageprocessing, consider the types of algorithms that might be useful after the offshoots thatDivision of Computer Engineering, SOE 15
  23. 23. MORPHOLOGICAL IMAGE PROCESSINGstick out from the sides of longer segments. There are several different approaches foreliminating these artifacts. For example, a program might loop through the imageremoving the pixel at the end of every line. These pixels are identifiedDivision of Computer Engineering, SOE 16
  24. 24. MORPHOLOGICAL IMAGE PROCESSINGby having only one black neighbor. Do this several times and the fuzz is removed at theexpense of making each of the correct lines shorter. A better method would loop throughthe image identifying branch pixels (pixels that have more than two neighbors). Startingwith each branch pixel, count the number of pixels in each offshoot. If the number ofpixels in an offshoot is less than some value (say, 5), declare it to be fuzz, and change thepixels in the branch from black to white.Another algorithm might change the data from a bitmap to a vector mapped format. Thisinvolves creating a list of the ridges contained in the image and the pixels contained ineach ridge. In the vector mapped form, each ridge in the fingerprint has an individualidentity, as opposed to an image composed of many unrelated pixels. This can beaccomplished by looping through the image looking for the endpoints of each line, thepixels that have only one black neighbor. Starting from the endpoint, each line is tracedfrom pixel to connecting pixel. After the opposite end of the line is reached, all the tracedpixels are declared to be a single object, and treated accordingly in future algorithms.Division of Computer Engineering, SOE 17
  25. 25. MORPHOLOGICAL IMAGE PROCESSING CHAPTER 3 MORPHOLOGICAL ALGORITHS3.1 Region FillingAdding the intelligence to detect a black inner point of sphere, we can use region fillingto fill up the sphere to be completely white. Fig:3.1• PruningPruning methods are an essential complement to the procedures that tend to leaveparasitic components that need to be ―cleaned up‖ by post processing. For example, theautomated recognition of hand printed characters.• Thickening The structuring elements have the same form as in thinning but with all 1’s and 0’s interchanged, However, a separate algorithm for thickening isseldom used in practice. The usual procedure is to thin the background instead.Division of Computer Engineering, SOE 18
  26. 26. MORPHOLOGICAL IMAGE PROCESSING3.2APPLICATIONS OF MORPHOLOGYMorphological SmoothingSince opening suppresses bright details smaller than the specified SE, and closingsuppresses dark details, they are often used in combination as morphological filters forimage smoothing and noise removalFig:3.2As expected, more details are removed as the size of SE increases. In the last result, theobject of interest is extracted almost completely (noise on the lower side could not beremoved completely due to its density).The technique shown before – an opening of the original image followed by closing theopening – is called sometimes an alternating sequential filtering. This processing is usedin automated image analysis, in whichresults at each step are compared to a specific metric.Morphological GradientDilation and erosion can be used in combination with image subtraction to obtain themorphological gradient g of animage as g = ( f ⊕b) −( f b)The dilation thickens regions in an image and the erosion shrinks them. Therefore, theirdifference emphasizes the boundaries between regions. If the SE is relatively small,Division of Computer Engineering, SOE 19
  27. 27. MORPHOLOGICAL IMAGE PROCESSINGhomogeneous areas will not be affected by dilation and erosion, so the subtraction tendsto eliminate them. The net result is an image with the gradient-like effect.EROSION MORHOLOGICALGRADIANTORIGINAL DIALATIONFig:3.33.3 Top‐hat and bottom‐hat transformationsCombining image subtraction with openings and closings results in top-hat and bottom-hat transformations. The top-hat transformation of a gray-scale image f is defines as fminus its opening:That ( f ) = f − ( f ���b)Similarly, the bottom-hat transformation of a gray-scale image f is defines as the closingof minus f: B( f) = f •b − fOne principal application of these transforms is in removing objects from an image byusing an SE in the opening and closing that does not fit the objects to be removed. Thedifference then yields an image with only the removedDivision of Computer Engineering, SOE 20
  28. 28. MORPHOLOGICAL IMAGE PROCESSINGobjects. The top-hat is used for light objects on a dark background and the bottom-hat –for dark objects on a light background.An important use of top-hat transformation is in correcting the effects of non-uniformilluminationNote the enhancement of detail in the background region below the lower part of thehorse’s head.Fig:3.4.Binary segmentation most simply is carried out by selecting connected components in theimage, using a seed image, a mask image (which is typically the actual image), and fillingselected connected components in the mask that have seeds in them. Here, the mask isused to clip the filling process. In a more complicated situation, typified by a binaryimage of touching coffee beans, you need to split binary connected components. This canbe done using the distance function and looking for low saddle points that are most easilycut through. How do you do that? Put the distance function upside-down. Then the seeds,which are the local maxima of the distance function (the points that are farthest from theDivision of Computer Engineering, SOE 21
  29. 29. MORPHOLOGICAL IMAGE PROCESSINGboundaries) are at the bottom of the inverted function. The boundaries are at the highestpoint, and the "low passes" through the saddle are on the boundaries of the catchmentbasins. Segmentation is achieved by filling the basins to define the watersheds, which areall the points that drain into the same basin.Similarly, grayscale segmentation usually proceeds by finding markers, or "seeds," andan image of catchment basins surrounded by walls at the boundaries. The catchmentfilling "mask" can be computed in various ways; a popular one is to use a properlysmoothed morphological gradient, which has large peaks at places where the imageintensity is rapidly varying -- a likely position to find a segmentation boundary. Fillingthen proceeds from the seeds into these basins.There are various ways to get the seeds. Two popular ones are tophat and h-dome transforms. The tophat is simpler, and you can envision its operation as follows.Suppose you have a dark grayscale image with some small bright regions. To identifythose regions, apply the tophat, using a SE that is larger than the extent of the regions.The opening is a Minoperation that removes those bright regions that are smaller indimension than the SE used in the opening. Then, subtracting this image with the thinpeaks cut off from the original image gives you just those peaks, plus some lowamplitude noise. The tophat is typically followed by a thresholding operation on thepeaks. Weve just described the whitetophat. There is a black tophat that is a dual to thewhite tophat, and it subtracts the original image from the closing with a SE. The blacktophat gives large pixel values in the result where there were small dark regions in theoriginal image.The h-domes are another method for finding local maxima. They use a grayscalereconstruction (seed filling) method, where the original image is the mask and the seed isderived from the mask by subtracting a constant value "h" from each pixel value.Reconstruction expands the seed into the original image (mask). This is visualized ashaving each local maximum of the seed expand horizontally until it hits a value of themask that is of equal or greater value, at which point it can expand no further. Tocomplete the h-dome transform, the filled seed is then subtracted from the original image,Division of Computer Engineering, SOE 22
  30. 30. MORPHOLOGICAL IMAGE PROCESSINGresulting in an image composed of the "domes" of local maxima of the original, none ofwhich can exceed the value h in size.You can find implementations of the tophat transform pixTophat() and the hdometransform pixHDome() in morphapp.c. We have implemented both black and whitetophat transforms, even though they are trivially related. Intuitively, applying a blacktophat to find small dark regions should be equivalent to applying a white tophat to theinverse of the image. (The inverse of an image is found by replacing each pixel by itsreflection in the light-dark axis; specifically, if the pixel has value v, it is replaced by thevalue 255 - v.) And, in fact, this is correct. These operations have exactly that simpleduality relation: the white tophat on an image is equal to the black tophat on the inverseof the image, and v.v. The proof, which uses the duality of the opening and closingoperations, is very simple. Let the opening of an image I with a structuring element S begiven by OS(I), and the closing of I by S be CS(I). From here on, due to a typographiclimitation of HTML, well suppress the "S". Denote the inverse of an image I by I,where I = 255 - I. The opening and closing are dual, in the sense that O(I) = C(I). (Notethat this is a different sense of "dual" than for the black and white tophats, which we arein the process of showing.) Denote the white tophat by Tw(I) = I - O(I) and the blacktophat by Tb(I) = C(I) - I. Then the black tophat on the inverse of I is given byTb(I) = C(I) - I = O(I) - I = 255 - O(I) - 255 + I = I - O(I) = Tw(I)which is the result that was to be proven. By the way, the duality relations for openingand closing, O(I) = C(I), or C(I) = O(I), can be stated in words in several ways. Heresone for the second of the pair: The closing of an image can be equivalently found byinverting the opening of the inverted image. This holds for binary as well as grayscale, ofcourse.High frequency noise, which is not well filtered by the white tophat, can be greatlyreduced by doing a closing first. Likewise, an opening is often necessary before a blacktophat. The size of the SE in the opening or closing can be comparable to that used in thetophat.Division of Computer Engineering, SOE 23
  31. 31. MORPHOLOGICAL IMAGE PROCESSING(Parenthetical note. For seeing the results clearly, we provide afunction pixMaxDynamicRange() that expands the dynamic range to cover the full set of256 values for an 8 bpp image. We let you do this with either a linear or log transform.The latter is useful for images that cover a large dynamic range to begin with and havesmall values that you wish to see and which appear black on a linear scale.)3.4 GranulometryGranulometry (in image processing) is a field that deals with determining the sizedistribution of particles in an image. In practice, particles seldom are neatly separated,which makes particle counting by identifying individual particles a difficult task.Morphology can be used to estimate particle size distribution indirectly, without havingto identify and measure every particle in the image. The approach is simple Withparticles of regular shapes simple. that are lighter than the background, the methodconsists ofapplying openings with SEs of increasing size. The opening of a particular size shouldhave the most effect on the particles of the same sizeThen, for each opening, the sum of the pixel values in the opening is computed. This sum(sometimes called the surface area) decreases as a function of increasing SE size sinceopening decreases the intensity of light features. This procedure yields a 1D array of suchnumbers: the sumof pixels as a function of SE size. To emphasize changes between successive openings,the differences between successive openings can be computed and plottedThe peaks in the plot are an indication of the predominant size distributions of theparticles in the image.Division of Computer Engineering, SOE 24
  32. 32. MORPHOLOGICAL IMAGE PROCESSINGFig:3.5We notice that intensity contributions from small dowels is almost eliminated in ―openingwith r = 20‖. As SE size increases, intensity contributions for largerFig:3.6A difference array: two distinct peaks clearly identify the presence ofDivision of Computer Engineering, SOE 25
  33. 33. MORPHOLOGICAL IMAGE PROCESSINGtwo dominant object sizes of the image.As the particles are lighter than the background, we use opening with increasing size ofstructuring elements, and compute the difference between the original image and itsopening. The histogram of that difference indicates the presence of three predominantparticle sizes in the input image3.5 Textural segmentationThe objective is to find the boundary between the two regions based on their texturalcontent.The objective is to find the boundary between the two regions based on their texturalcontent>Closing with successively larger structuring elements>When the size of the structuring element corresponds to that of the small blobs, they areremoved> A single opening is performed with a structuring element that is larger than theseparation between the large blobs-> dark region on the right>Then, a simple thresholding yields the boundaryDivision of Computer Engineering, SOE 26
  34. 34. MORPHOLOGICAL IMAGE PROCESSINGTextural segmentation of lizardFig:3.7Division of Computer Engineering, SOE 27
  35. 35. MORPHOLOGICAL IMAGE PROCESSING CHAPTER 4 MORPH AGE4.1 BASICS:Morph Age is an application for morphing faces and warping images and movies on MacOS X.Morph Age works by allowing you to define curves on one or more images. Any changemade on the curves is reflected on the resulting image through the correspondingdistorsion and morphing effect. Morph Age can also work from QuickTime movies ascurves can be animated with keyframed motion. One talking face can be morphed intoanother talking face as they are talking!Morph Age comes in 2 different versions, Regular and Pro.  Regular has most of the latest advances in morphing features, including Smart Assist and interactive preview.  Pro version has additional support for video morphing and warping, allowing frame accurate processing and advanced keyframed animation.Morph Age is an application for morphing/warping images and movies on Mac OS X,such as faces, and save the result to a QuickTime movie. Morph Age works by allowingyou to define curves on one or more images. Any change made on the curves is reflectedon the resulting image through the corresponding distorsion and morphing effect. MorphAge can also work from QuickTime movies as curves can be animated with keyframedmotion. One talking face can be morphed into another talking face as they are talking!DEFINITELY MACMorph Age is a Mac software from the start. You can import various image formats fromany sources, including direct access to your iPhoto and iMovie media. You can even useyour iSight, which is bundled with almost every mac nowadays, directly from withinDivision of Computer Engineering, SOE 28
  36. 36. MORPHOLOGICAL IMAGE PROCESSINGMorph Age to import a picture or animation. The rendered animation isin QuickTime format, enabling further composition in Final Cut Pro or iMovie, or evenexport it to your video iPod!CONTROLLING THE MORPHING ANIMATIONMorph Age can animate warp curves independently, so that different parts of the imagemoves at different times (the eyes, then the ears, then the mouth...). Also, animationeffects are available, such as springy motion. Morph Age shows the result in real time, sothat you can quickly and easily prototype the transformation.ZOOMINGZooming allows accurate curve placement. This is necessary as Morph Age offers sub-pixel accuracy. The real-time preview rendering can also be zoomed and can serve toassist precise curve placement.COLORIZINGMorph Age has colorizing options that makes it possible for Hulk-like warp effects. Thisworks by allowing the user to define, independently for each curve, a color that will"bleed" on the underlying image parts. This color bleeding is animated consistently withthe deformation.LAYERSLayers in Morph Age is a way to express that parts of the image are above others. This isused to express that the chin is above the clothes and that whenever the chin is moveddownwards, it should pass over them (and not under).REAL-TIME RENDERINGDivision of Computer Engineering, SOE 29
  37. 37. MORPHOLOGICAL IMAGE PROCESSINGMorph Age uses advanced GPU rendering techniques, allowing real-time preview evenfor mega-pixels images.4.2 MORPHING SOFTWARES1.FRACTER 1.1Fractracer is a program for creating, exploring and rendering high-complexity 3D objects.Fractracer uses powerful script language for defining objects, scenes, and GUI elements.Any created object can be exported to use in other modeling software.2.AV MP3 Player MorphingMorph music by changing voice, tempo as well as adding effects and beats. Play, capture& record music, convert, rip, and burn MP3s & CDs. Edit CD Cover & Label. Fullfunctions included to make unique CDs, movies, audio & video clips.3.Free Fun Morphing 2.1Free Fun Morphing creates a sequence of frames which are the transformation of thesource image to target image, giving the appearance that the source image "becomes" thetarget.4.VidMorph ProMix Video and Image morphing in one media. Create video effects from digital photos,images, home videos, movies. No technical skills required - anyone can make a photoanimation in just seconds! Save morphs in Flash, WMV, ASF, AVI, Animated GIF, ipo5.AbroSoft FantaMorphFantaMorph Deluxe is designed to create fantastic face morph and face composite in realtime. With our revolutionary rendering engine and a super friendly user interface,creating face morph or face composite has never been easier and faster!Division of Computer Engineering, SOE 30
  38. 38. MORPHOLOGICAL IMAGE PROCESSING6.FX MorphCreate morphing and warping images and animation sequences from still images7. Face MorpherCreate animated transitions of one face into another in just minutes with this fullyautomated face morphing program. It guesses basic spots automatically and makesrealistic animations saving you time and effort.4.3 MORPHOLOGY IN REAL WORLDWith the advent of films like Terminator 2, Stargate, and Interview with the Vamipre,and music videos such as Michael Jacksons "Black or White" video, a morphing crazeswept Hollywood. Everyone just had to have some sort of image transformation in theirproject, no matter how small or insignificant. But how is it all done? And moreimportantly, what is it?Morphing is a technique used to transfer from one image to another. However, before yourun out and try it on your own, we should mention there is quite a bit more to it than that.Morphing involves taking two elements, from which you want to change from one to theother. The idea is to make it appear as if one item is physically changing into the other.The animators select points which are simalar on the two elements. For example eyes,ears, hair, and other such features work well for faces. When moving from two objectsthat are very similar, a car to a car, or a person to a person, its easy to find points that canshift well. But on other objects, you need to stretch a little. Shadows should always bematched. Open spaces always can be altered into other open spaces.An easier application of morphing involves working with two 3D objects. In thecomputer the morph program can create intermediate models for the change, so that itlooks much more like the first model is moving and reforming into the second. A goodexample is the mask worn by the aliens in Stargate. When activated by the wearer, theDivision of Computer Engineering, SOE 31
  39. 39. MORPHOLOGICAL IMAGE PROCESSINGmasks would pull back to reveal the face of the person. The animators make it look likethe masks were pulling away by creating a model of the mask and then basicallymorphing it into a small pack located on the wearers back. This provided a very goodillusion.The first major application of morphing technology was 1991s Terminator 2: JudgementDay. Industrial Light and Magic had already suceeded in modeling and animating ametallic creature in the shape of actor Robert Patrick, but making the transitions from themodel to the actor was another problem. Morphing allowed the team to work from themodel, slowing blending in the features of the actor, providing a smooth transformationas the android assumed his new shape. Since this intial offering, several science fictionfilms have used the morphing idea for shapeshifters of various kinds. Star Trek has beenan especially enthusiastic user of morphing, tarting with the creature in Star Trek VI: TheUndiscovered Country, and now with the shape-changing Odo and his entire race on thesyndicated television showStar Trek: Deep Space Nine.Another good example of a morph from an actor to a 3D computer model was evidentin The Mask. In the movie the premise was that a magical mask allowed the wearer tomanipulate his/her body into all kinds of contortions, mostly resembling cartoonanimation. ILM created 3D models and animated them, then used morphing programs toease the transition from Jim Carrey to the model, and back.Morph programs are also available to anybody. There are several different typesavailable, and there are many sites on the web which talk more about this technology. Seetherelated links below for some good pages.Morphing is just one of the latest crazes in the movies and TV. Music videos love tomake extensive use of this tool. Michael Jacksons "Black or White" video was one of thefirst, with a very interesting morph sequence from person to person. However, you canalways get too much of a good thing, and many of the morphs are not much more than agratuitous use of the technology. Todd Vaziri has written a good page, Why Morph?,describing the basics of morphing, and what should be done, and what shouldnt.Division of Computer Engineering, SOE 32
  40. 40. MORPHOLOGICAL IMAGE PROCESSINGMorphing has become quite a big thing in Hollywood, but along with the obvious uses,its now evolving into much more of a tool than a gimmick. Useful applications havebeen utilized in Dragonheart,Twister, and numerous other movies. Much like otherprograms it will continue to be developed and expanded for other purposes.Division of Computer Engineering, SOE 33
  41. 41. MORPHOLOGICAL IMAGE PROCESSING CONCLUSIONThe purpose of morphological processing is primarily to remove imperfections addedduring segmentation. The basic operations are erosion and dilation .Using the basicoperations we can perform opening and closingMore advanced morphological operationcan then be implemented using combinations of all of these.Division of Computer Engineering, SOE 34
  43. 43. MORPHOLOGICAL IMAGE PROCESSINGDivision of Computer Engineering, SOE 36