1 / 35

Morphological Image Processing (laboratory)

Morphological Image Processing (laboratory). C. Andr és Méndez G. May-2013. Where to find the presentations?. http://profs.sci.univr.it/~mendezguerrero. Overview: Morphology. Tool for extracting components of image using shapes. Described in terms of set operations.

aolani
Download Presentation

Morphological Image Processing (laboratory)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Morphological Image Processing (laboratory) C. Andrés Méndez G. May-2013

  2. Where to find the presentations? http://profs.sci.univr.it/~mendezguerrero

  3. Overview: Morphology • Tool for extracting components of image using shapes. • Described in terms of set operations. • Basic set operations: • Suppose A and B are sets in Z2 . • Translation: Bx = {c: c = b + x, for x in B}. • (Translation of B by x moves the set so that its origin is at x.) • Reflection: hat (B) = {x : x = -b, for b in B}. • Reflection has the effect of flipping • Complement: Ac = {x: x not in A}. • Difference: A - B = {x: x in A but x not in B}. • Difference is A intersect Bc • Morphological image operations involve two sets: A and B. Usually A is an image and B is a structuring element. • Move position of B relative to A and perform set operations. • Matlab implements 4 morphological operations for binary or uint8: imerode, imdilate, imclose and imopen. • A general morphological operator bwmorph is available for binary images. • Must consider behavior at the boundary. • The key to having effective morphological operations is picking a good structuring element.

  4. Structuring Element (SE) • Usually a small image that is used like a spatial filter. • Has 1's in positions corresponding to elements in the set. • Has 0's elsewhere. • The locations of the 1's are called the neighborhood defined by the structuring element. • The location of the origin is important: • The origin isn't always in the center. • Two structuring elements which have the same bit pattern, but different origins behave differently. • To use a mask represented as an array with a Matlab morphological operation, use strel to convert it to the appropriate representation.

  5. Erosion • A eroded by B = {x : Bx is in A} • The symbol for erosion is a minus sign with a circle around it. • Erosion reduces the size of objects, eliminating features that are less than the scale of the neighborhood as defined by the structuring element. • Matlab definition of erosion (works for graylevel as well as binary images): A eroded by B = {x : x = min pixels in A in neighborhood Bx } • Matlab operation is imerode • Matlab handles boundaries by assigning pixels beyond the,boundary, the maximum value possible for data type (1 for binary, 255 for uint8).

  6. Erosion review

  7. Erosion –Esercizio 1 • Creare un quadrato 9x9 • Creare tre matrci 3x3 • Con il comando strel creare dalle tre matrici tre SE e visualizzarli • Effettuare una erosione standard e con zero padding

  8. Matlab and the processing of border pixels • Morphological functions position the origin of the structuring element, its center element, over the pixel of interest in the input image. For pixels at the edge of an image, parts of the neighborhood defined by the structuring element can extend past the border of the image. • To process border pixels, the morphological functions assign a value to these undefined pixels, as if the functions had padded the image with additional rows and columns. The value of these padding pixels varies for dilation and erosion operations. The following table describes the padding rules for dilation and erosion for both binary and grayscale images.

  9. Dilation • A dilated by B = {x : hat(B)x is in A}. • The symbol for dilation is a plus sign with a circle around it. • Dilation expands the size of objects on the scale of the structuring element neighborhood. • Matlab definition of dilation (works for graylevel as well as binary images): A dilated by B = {x : x = max pixels in A in neighborhood Bx } • Matlab operation is imdilate. • Matlab handles boundaries by assigning pixels beyond the boundary, the minimum value possible for data type (1 for binary, 255 for uint8). • Note: The Matlab version appears to follow Gonzales and Woods and reflects the structuring element before applying the mask operation. This doesn't appear to be documented. There is some inconsistency about the definition of dilation and hence the operations that depend on it. For example, Fundamentals of Digital Image Processing by Jain defines dilate without reflecting the structuring element B. This distinction is important if the structuring element is not symmetric.

  10. Dilation–Esercizio 2 • Stesse strutture del Esercizio1 • Creare un quadrato 9x9 • Creare tre matrici 3x3 • Con il comando strel creare dalle tre matrici tre SE e visualizzarli • Effettuare una dilatazione standard e con zero padding

  11. Opening • A opened by B is an erosion of A by B followed by a dilation of A by B. • The symbol for the open operation is a small open circle. • Open smooths contours, breaks narrow isthmuses and eliminates little knobs. • Matlab defines open in terms of erosion and dilation. • The definition works on both grayscale and binary images. • Matlab operation is imopen.

  12. Opening Example

  13. Opening–Esercizio 3 • Stesse strutture del Esercizio1 • Creare un quadrato 9x9 • Creare tre matrici 3x3 • Con il comando strel creare dalle tre matrici tre SE e visualizzarli • Effettuare una apertura standard e con zero padding • Creare altri tre SE di soli 1 di dimensioni 3x3, 5x5 e 7x7 • Effettuare una apertura standard dell’immagine complemento di macchie.tif (Matlab command- imcomplement)

  14. Closing • A closed by B is a dilation of A by B followed by an erosion of A by B. • The symbol for the open operation is a small closed circle. • Close fuses narrow breaks, eliminates small holes and fuses gaps. • Matlab defines close in terms of erosion and dilation. • The definition works on both grayscale and binary images. • Matlab operation is imclose.

  15. Closing example

  16. Closing- Esercizio 4 • Stesse strutture del Esercizio1 • Creare un quadrato 9x9 • Creare tre matrici 3x3 • Con il comando strel creare dalle tre matrici tre SE e visualizzarli • Effettuare una chiusura standard e con zero padding • Probare con una nueva matrice 9x9 • Creare altri tre SE di soli 1 di dimensioni 3x3, 5x5 e 7x7 • Effettuare una chiusura standard dell’immagine compemento di macchie.tif • (Matlab command- imcomplement)

  17. Boundary detection • If A is an image, and B a small structuring element consisting of points symmetrically placed about the origin, then we can define the boundary of A by any of the following methods: • In each definition the minus refers to set diference. • Note that the internal boundary consists of those pixels in A which are at its edge; the external boundary consists of pixels outside A which are just next to it, and that the morphological gradient is a combination of both the internal and external boundaries.

  18. Boundary detection

  19. Boundaries-Esercizio 5 • Open rice.png • Set a threshold to obtain a binary image • (ricethresholded=rice>threshold) • Get • Internal boundary • External Boundary • Morphological Gradient • Note: You must use logic gates to get the set difference

  20. Hit-or-Miss Transformation, example (1) This is a powerful method for finding shapes in images. As with all other morphological algorithms, it can be defined entirely in terms of dilation and erosion; in this case, erosion only. Suppose we wish to locate 3x3 square shapes, such as is in the centre of the following image

  21. Hit-or-Miss Transformation, example (2) If we performed an erosion with B being the square structuring element, we would obtain the result given in the following figure The result contains two pixels, as there are exactly two places in A where B will fit. Now suppose we also erode the complement of A with a structuring element C which fits exactly around the 3x3 square. (we assume (0,0) is the centre of C)

  22. Hit-or-Miss Transformation, example (3) If we now perform the erosion we would obtain the result The intersection of the two erosion operations would produce just one pixel at the position of the centre of the 3x3 square in A, which is just what we want (red circle). If had contained more than one square, the final result would have been single pixels at the positions of the centres of each. This combination of erosions forms the hit-or-miss transform.

  23. Hit-or-Miss Transformation, example (4) In general, if we are looking for a particular shape in an image, we design two structural elements: B1 which is the same shape, and B2 which fits around the shape. We then write B=(B1,B2) and the Hit-and-miss transform as

  24. Esercizio 6 • Implement the Hit-or-Miss transform example (explained in the last 4 slides) • Use the Hit-or-Miss transform to find the hyphen between the words ”cross -correlation” in text.tif

  25. Frame Differencing • To find the person in frame 62, we compare with frames 47 and 77. • diff1b = abs(frame47-frame62); • diff2b = abs(frame77-frame62); • motionb = min(diff1b, diff2b);

  26. From Motion to Shape • Step 1: Thresholding

  27. From Motion to Shape • Drawback, manual selection • Manual parameters make methods fragile

  28. From Motion to Shape • Choosing a threshold manually: • OK for toy example. • bad practice oftentimes. • sometimes, unavoidable or extremely convenient. • For our example: thr = 10.

  29. From Motion to Shape • We should identify the biggest “area”. • Connected Component Analysis. • What is a connected component? • Set of pixels such that you can find a white-pixel path from any of them to any of them. • 4-connected, 8-connected.

  30. Connected components in Matlab • bwlabel second argument: 4 or 8-connected. • label2rgb: assigns random colors, to make it easy to visualize.

  31. Identifying the Larges Component • labels is an image of connected component IDs. • 0 is the ID of the background, which we ignore. • number is the number of connected components. • We can count the pixels of each component.

  32. Result: Isolated Shape

  33. Using Dilation • For every white pixel in original image: • Make all neighbors white in result. • What is a neighbor? • Specified as an extra parameter.

  34. Erosion • For every black pixel in original image: • Make all neighbors black in result. • Neighborhood: 2 nd argument.

More Related