30
Morphological Operators CS/BIOEN 4640: Image Processing Basics February 23, 2012

Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Morphological Operators

CS/BIOEN 4640: Image Processing Basics

February 23, 2012

Page 2: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Common Morphological Operations

I Shrinking the foreground (“erosion”)I Expanding the foreground (“dilation”)I Removing holes in the foreground (“closing”)I Removing stray foreground pixels in background

(“opening”)I Finding the outline of the foregroundI Finding the skeleton of the foreground

Page 3: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Pixel Neighborhoods

Remember the two definitions of “neighbors” that we’vediscussed:

4 Neighborhood 8 Neighborhood

Page 4: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Erosion Example

Change a foreground pixel to background if it has abackground pixel as a 4-neighbor.

Page 5: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Dilation Example

Change a background pixel to foreground if it has aforeground pixel as a 4-neighbor.

Page 6: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Structuring Element

DefinitionA structuring element is simply a binary image (ormask) that allows us to define arbitrary neighborhoodstructures.

Example:

This is the structuring element for the 4-neighborhood.

Page 7: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Binary Images as Sets

We can think of a binary image I(u, v) as the set of allpixel locations in the foreground:

QI = {(u, v) | I(u, v) = 1}

To simplify notation, we’ll use a single variable for acoordinate pair, p = (u, v). So,

QI = {p | I(p) = 1}

Page 8: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Set Operations = Point OperationsI Complement = Inversion

Let I denote image inversion (pointwise NOT)

QI = QI = {p ∈ Z2 | p /∈ QI}

I Union = ORLet I1 ∨ I2 be pointwise OR operation

QI1∨I2 = QI1 ∪QI2

I Intersection = ANDLet I1 ∧ I2 be pointwise AND operation

QI1∧I2 = QI1 ∩QI2

Page 9: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

More Image Operations

(Instead ofQI, we’ll just use I to denote the set)

I Translation: Let d ∈ Z2

Id = {(p + d) | p ∈ I}

I Reflection:

I∗ = {−p | p ∈ I}

Page 10: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Dilation

DefinitionA dilation of an image I by the structure element H isgiven by the set operation

I ⊕ H = {(p + q) | p ∈ I, q ∈ H}

Alternative definition: Take the union of copies of thestructuring element, Hp, centered at every pixel locationp in the foreground:

I ⊕ H =⋃p∈I

Hp

Page 11: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Dilation Algorithm

Uses equivalent formula I ⊕ H =⋃

q∈H Iq:

Input: Image I, structuring element HOutput: Image I′ = I ⊕ H

1. Start with all-zero image I′

2. Loop over all q ∈ H3. Compute shifted image Iq

4. Update I′ = I′ ∨ Iq

Page 12: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Erosion

DefinitionA erosion of an image I by the structure element H isgiven by the set operation

I H = {p ∈ Z2 | (p + q) ∈ I, for every q ∈ H}

Alternative definition: Keep only pixels p ∈ I such thatHp fits inside I:

I H = {p | Hp ⊆ I}

Page 13: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Duality of Erosion and Dilation

Erosion can be computed as a dilation of thebackground:

I H = (I ⊕ H∗)

Same duality for dilation:

I ⊕ H = (I H∗)

Page 14: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Erosion Algorithm

Uses dual, I H = (I ⊕ H∗)

Input: Image I, structuring element HOutput: Image I′ = I H

1. Start with inversion, I′ = I2. Dilate I′ with reflected structure element, H∗

3. Invert I′

Page 15: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Properties of Dilation

Similar to convolution properties, we need to assume theimage domains are large enough that operations don’t“fall off” the edges.

Commutativity:

I ⊕ H = H ⊕ I

Means we can switch the roles of the structuring elementand the image

Page 16: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Properties of Dilation

Associativity:

I1 ⊕ (I2 ⊕ I3) = (I1 ⊕ I2)⊕ I3

Means that we can sometimes break up a big structuringelement into smaller ones:

That is, if H = H1 ⊕ H2 ⊕ . . .⊕ Hn, then

I ⊕ H = (((I ⊕ H1)⊕ H2)⊕ . . .⊕ Hn)

Page 17: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Properties of Erosion

I It is NOT commutative:

I H 6= H I

I It is NOT associative, but:

(I H1) H2 = I (H1 ⊕ H2)

Page 18: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Some Particular Dilation Operators

I Identity: id = {(0, 0)}

I ⊕ id = id⊕ I = I

I Shift by k pixels in x: Sx = {(k, 0)}I Shift by k pixels in y: Sy = {(0, k)}

Page 19: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Opening

Opening operation is an erosion followed by a dilation:

I ◦ H = (I H)⊕ H

Stray foreground structures that are smaller than the Hstructure element will disappear. Larger structures willremain.

Page 20: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Closing

Closing operation is a dilation followed by an erosion:

I • H = (I ⊕ H) H

Holes in the foreground that are smaller than H will befilled.

Page 21: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Improving a Segmentation

Original image Initial threshold

Page 22: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Improving a Segmentation

Original image After opening

Page 23: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Improving a Segmentation

Original image After closing

Page 24: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Outline

The outline image B(u, v) of a binary object can becomputed using a dilation followed by a subtraction (orXOR operation):

I′ = I H

B(u, v) = XOR(I′(u, v), I(u, v))

Page 25: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Outline

Page 26: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Outline Example

Binary segmentation After outline operation

Page 27: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Skeletonize

Repeatedly run erosion, stop when 1-pixel thick

Page 28: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Grayscale Morphology

I We can also apply morphological operators tograyscale images.

I Now our structuring elements are real-valuedH(i, j) ∈ R. That is, they are grayscale images.

I Need to make a distinction between 0 and “don’tcare” entries.

Page 29: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Grayscale Morphology

Dilation:

(I ⊕ H)(u, v) = max(i,j)∈H

{I(u + i, v + j) + H(i, j)}

Erosion:

(I H)(u, v) = min(i,j)∈H

{I(u + i, v + j) + H(i, j)}

Page 30: Morphological OperatorsSecure Site my.eng.utah.edu/~cs4640/slides/Lecture11.pdf · Common Morphological Operations I Shrinking the foreground (“erosion”) I Expanding the foreground

Link to ImageJ Morphology Package

http://rsbweb.nih.gov/ij/plugins/gray-morphology.html