Image and Multidimensional Signal Processing Colorado School of Mines

advertisement

Colorado School of Mines

Image and Multidimensional

Signal Processing

Professor William Hoff

Dept of Electrical Engineering &Computer Science http://inside.mines.edu/~whoff/

Morphological Image Processing

Colorado School of Mines Department of Electrical Engineering and Computer Science

2

Preview

• “Morphological” = shape, form, structure

• Notes

– Useful for extracting and describing image component regions

– Usually applied to binary (black & white, or 0 & 1) images

– Based on set theory

• Key topics:

– Set theory

– Binary operations: dilation, erosion, opening, closing

– Connected components

– Morphological algorithms

– Gray scale morphology

3

Binary Images

• Obtained from

– Thresholding gray level images (e.g., Matlab’s “ im2bw ”)

– Or, as a resulting product of feature detectors

• Often want to count or measure shape of 2D binary image regions

• Typical applications

– Objects on a conveyor belt

– Characters and text, maps

– Chromosomes

– Fingerprints

– Circuit boards

– Overhead aerial images

4

Set Theory Concepts

• For 2D binary images, A is the (unordered) set of pairs ( x,y ) such that the image value at ( x,y ) is equal to 1

A

  

| I

A x y

The vertical bar means “such that”

• “Union” of two sets A and B

– The set of elements belonging to A, B , or both

A

B

“Intersection” of two sets A and B

– The set of elements belonging to both A and B

A

B

• w “is an element of” set A w

A

5

Set Theory Concepts

• “Complement”

– The set of elements that are not in A

A c

  w | w

A

• “Difference” of two sets A and B

– The set of elements belonging to

A , but not to B

  

|

,

B

Comma means “and”

• “Subset”

– A is a subset of B if every element of A is also in B

A

B

• The empty set { }

6

Set Operations

A

  

| I

A x y

B

  

| I

B x y

7

Reflection and Translation

ˆ 

 w w

  b , for b

B

 z

 c c

  z , for b

B

8

Structuring Elements

• Morphological operations are defined based on “structuring elements”

• A structuring element is a small set or subimage, used to probe for structure

• Examples

9

Erosion

• The erosion of set A by set (i.e., structuring element) B is

AӨB =

 z |

  z

A

• Interpretation: shift B by z , if it is completely inside A , output a 1

• Example

Origin of B

1 1 1

1

1

1

1 1 1 1 1

B

A

A ӨB

10

Erosion Examples

w w w/2

A ӨB

Radius r r

A ӨB w w w

A ӨB

11

• Erosion enlarges holes, breaks thin parts, shrinks object

• Is not commutative

AӨB ≠ BӨA

Erosion

A

B

A ӨB

12

Dilation

• The dilation of set A by set (structuring element) B is

A

 

 z |

  z

A



• Interpretation: reflect B , shift by z , if it overlaps with A , output a 1 at the center of B

• Example

Origin of B

1 1

1 1

B

1

1 1

1 1

1

B

ˆ

1

A

A

B

13

• Example

Another dilation example

Origin of B

1

1

1

1 1

A

1

1

1

B

A

B

Colorado School of Mines Department of Electrical Engineering and Computer Science

14

Dilation Examples

w w w/2

A

B

Radius r w w r

A

B w

A

B

15

A

Dilation Example

B A

B

16

• Dilation fills in holes, thickens thin parts, grows object

Dilation

A

B

A

B

17

Dilation Properties

• Is commutative

A

  

• and associative

B A

A

 

B

C

 

A

B

 

C

• Proof of commutative property

A

 

 z |

  z

A



– If we translate both sets, the intersection area is the same

|

ˆ  

 z



– If we reflect both sets, the intersection area is the same

|

  z

B A

B

A

B

ˆ z

18

Duality of Dilation and Erosion

( A

Ө

B) c = A c 

• Proof

AӨB =

 z |

  z

A

 z |

  z

A c  

(AӨB) c =

 z |

  z

A c  

 c z |

  z

A c  

A c  ˆ

Recall that A c means the complement of set A

If set ( B ) z

is contained in A , then the intersection of ( B ) z

with the complement of A is empty

Complement both sides

By the definition of dilation

19

Example

Origin of A

1

1

1

1

A

Origin of B

1 1

1

B

AӨB

(AӨB) c

A c

A c 

20

Matlab examples

• Make a structuring element

– SE = strel('square', W) or

– SE = strel('disk', R )

• Dilation and erosion

– imdilate(IM, SE)

– imerode(IM, SE)

• Try image ‘blobs.png’

21

Opening

• Opening – an erosion followed by a dilation

– Use the same structuring element B for both

A  B

A

B

B

• Is the union of all translates of B, that fit into A

A B

     z z

A

The opening of the dark-blue square by a disk, resulting in the light-blue square with round corners.

Colorado School of Mines http://en.wikipedia.

org/wiki/Mathemat ical_morphology

Department of Electrical Engineering and Computer Science

22

Opening

• Intuitive description

– Let B be a disk

– The boundary of the opening is the points in B that reach the farthest into A as B is rolled around inside of A

Colorado School of Mines Department of Electrical Engineering and Computer Science

23

Closings

• Closing – a dilation followed by an erosion

– Use the same structuring element B for both

A

B

A

B

B

• Take the union of all the translates of B that do not intersect A; the closing is the complement of that

The closing of the dark-blue shape (union of two squares) by a disk, resulting in the union of the dark-blue shape and the light-blue areas. http://en.wikipedia.

org/wiki/Mathemat ical_morphology

Colorado School of Mines Department of Electrical Engineering and Computer Science

24

Closings

• Intuitive description

– Let B be a disk

– We roll B around the outside of A

– The boundary of the closing is the points of B that just touch A

Colorado School of Mines Department of Electrical Engineering and Computer Science

25

Example - opening

B

26

Example - closing

B

27

Openings and Closings

• Are duals of each other

A

B

 c 

• Properties

A c 

A B A

A is a subset of

• Once an image has been opened (or closed), the re-application of the same operation has no effect

A

A

B

B

B

B

A

A  B

B

28

Colorado School of Mines Department of Electrical Engineering and Computer Science

29

Matlab examples

• Make a structuring element

– SE = strel('square', W) or

– SE = strel('disk', R, N)

• Dilation and erosion

– imopen(IM, SE)

– imclose(IM, SE)

• Try image ‘blobs.png’

30

Connected Components

4-connected

• Define adjacency

– 4-adjacent

– 8-adjacent

• Two pixels are connected in S if there is a path between them consisting entirely of pixels in S

• S is a (4- or 8-) connected component (“blob”) if there exists a path between every pair of pixels

• “Labeling” is the process of assigning the same label number to every pixel in a connected component

8-connected

31

Example

• Hand label simple binary image

1

1

1 1

1 1

1 1

1 1

1 1

Binary image Labeled image

(4-connected)

Labeled image

(8-connected)

Colorado School of Mines Department of Electrical Engineering and Computer Science

32

A Fast Labeling Algorithm

• One pass through image to assign temporary labels and record equivalences

• Second pass to replace temporary labels with equivalence labels

• Let

– B(r,c) is the input binary image

– L(r,c) is the output image of labels

• Side note – faster labeling algorithms do exist. They use 2x2 blocks to search for connected components and use the fact that all the pixels within the block are 8-connected.

• C. Grana, D. Borghesani, and R. Cucchiara. “Fast block based connected components labeling.”

Proc of ICIP, pages 4061-4064, 2009.

33

for c=1 to MAXCOL for r=1 to MAXROW

{ if B(r,c) == 0 then else

L(r,c) = 0;

{

{

% if pixel not white, assign no label

34

Example

1 1 1

1 1 1

1 1 1

1 1 1

Binary image Temporary labels after 1 st pass

Final (equivalence) labels after 2 nd pass

Colorado School of Mines Department of Electrical Engineering and Computer Science

35

Matlab Example

• Labeling connected components

(white blobs)

– im2bw

• threshold to convert to binary image

– bwlabel

• do connected component labeling

• generate an image of labels

– label2rgb

• for visualization

• converts each label to a random color

• If we want to find black blobs

– imcomplement

• Flip black and white regions

– then repeat steps

Image Fig9-16(a).jpg

36

>> I = imread('Fig9.16(a).jpg');

>> imshow(I,[])

>> whos

Name Size Bytes Class Attributes

I 512x512 262144 uint8

>> BW = im2bw(I, graythresh(I));

>> figure, imshow(BW)

>> [L,num] = bwlabel(BW);

>> figure, imshow(L,[])

>> num num =

17

>> RGB = label2rgb(L);

>> figure, imshow(RGB)

>> BW = imcomplement(BW);

>> [L,num] = bwlabel(BW);

>> RGB = label2rgb(L);

>> figure, imshow(RGB)

37

Summary / Questions

• Morphological operations on binary images involve a “structuring element”.

– A structuring element is a small subimage, used to probe for structure.

• Morphological operations are useful for:

– Eliminating small regions or filling in “holes”.

– Finding “connected components”.

• What is a “connected component”?

38

Download