practical image and video processing using...

48
Lecture 10 – Morphological Image Processing (courtesy of Oge Marques) Practical Image and Video Processing Using MATLAB® By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Upload: others

Post on 12-Mar-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Lecture 10 – Morphological Image Processing

(courtesy of Oge Marques)

Practical Image and Video Processing Using MATLAB®

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 2: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

What will we learn?

What is mathematical morphology and how is it used in image processing?

What are the main morphological operations and what is the effect of applying them to binary and grayscale images?

What is a structuring element and how does it impact the result of a morphological operation?

What are some of the most useful morphological image processing algorithms?

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 3: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

What is mathematical morphology?

Mathematical morphology is a branch of image processing which has been successfully used to provide tools for representing, describing, and analyzing shapes in images.

Initially developed by Jean Serra in the early 1980s

Named after the branch of biology that deals with the form and structure of animals and plants.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 4: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

What is mathematical morphology?

Basic principle: the extraction of geometrical and topological information from an unknown set (an image) through transformations using another, well-defined, set, known as structuring element (SE).

In morphological image processing, the design of SEs, their shape and size, is crucial to the success of the morphological operations that use them.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 5: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Fundamental concepts and operations

Basic set operations:

Complement

Difference

Translation

Reflection

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 6: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Fundamental concepts and operations

Basic set operations

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 7: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Fundamental concepts and operations

Logical equivalents of set theory operations

Intersection ~ logical AND

Similarly: Complement ~ logical NOT

Union ~ logical OR

Difference ~ A AND (NOT B)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

FUNDAMENTAL CONCEPTS AND OPERATIONS 275

(a) (b)

(c) (d)

(e) (f)

Figure 13.1 Basic set operations: (a) set A ; (b) translation of A by x = (x1 , x2); (c) set B ; (d)

reflection of B ; (e) set A and its complement Ac ; (f) set difference (A − B ).

Theequivalent expression using conventional image processing notation would be:

C (x, y) =

⇢1 if A (x, y) and B (x, y) areboth 1

0 otherwise(13.6)

This expression leads quite easily to a single MATLAB statement that perform the

intersection operation using the logical operator AND (&). Similarly, complement can be

obtianed using theunary NOT (~) operator, set union can beimplemented using the logical

operator OR (| ) and set difference (A − B ) can be expressed as ( A & ~B) . Figure 13.2

showsrepresentativeresults for twobinary input images. Pleasenotethat wehavefollowed

theIPT convention, representing foreground(1-valued) pixelsaswhitepixelsagainst ablack

background.

13.2.1 The structuring element

The structuring element (SE) is the basic neighborhood structure associated with morpho-

logical image operations. It isusually represented asasmall matrix, whoseshape and size

Page 8: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Fundamental concepts and operations

Logical equivalents of set theory operations

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 9: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

The structuring element

The structuring element (SE) is the basic neighborhood structure associated with morphological image operations.

It is usually represented as a small matrix, whose shape and size impact the results of applying a certain morphological operator to an image.

Although a structuring element can have any shape, its implementation requires that it be converted to a rectangular array. For each array, the shaded squares correspond to the

members of the SE whereas the empty squares are used for padding, only.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 10: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

The structuring element

Examples:

square cross

MATLAB functions (see Examples 13.1 and 13.2): strel

getsequence

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 11: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Dilation and erosion

The two fundamental morphological image operations.

Dilation: a morphological operation whose effect is to “grow” or “thicken” objects in a binary image. The extent and direction of this thickening is

controlled by the size and shape of the structuring element.

Mathematically:

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 12: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Dilation and erosion

Dilation – geometrical interpretation

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 13: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Dilation and erosion

Dilation – MATLAB example (13.3)

a = [0 0 0 0 0;

0 1 1 0 0;

0 1 1 0 0;

0 0 1 0 0;

0 0 0 0 0]

se1 = strel('square',2)

b = imdilate (a,se1)

se2 = strel('rectangle', [1 2])

c = imdilate (a,se2)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 14: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Dilation and erosion

Erosion: a morphological operation whose effect is to “shrink” or “thin” objects in a binary image.

The direction and extent of this thinning is controlled by the shape and size of the structuring element.

Mathematically:

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 15: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Dilation and erosion

Erosion – geometrical interpretation

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 16: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Dilation and erosion

Erosion– MATLAB example (13.4)

a = [ 0 0 0 0 0 ; 0 1 1 1 0; 1 1 1 0 0; 0 1 1 1 1; 0 0 0 0 0]

se1 = strel('square',2)

b = imerode (a,se1)

se2 = strel('rectangle', [1 2])

c = imerode (a,se2)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 17: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Dilation and erosion

Erosion and dilation are dual operations

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 18: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Dilation and erosion Erosion and dilation can be interpreted in terms of

whether a SE fits or hits an image (region)

Erosion:

Dilation:

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 19: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Compound operations

Opening: erosion followed by dilation

Mathematically:

or:

In MATLAB: imopen (Tutorial 13.1)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 20: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Compound operations

Opening: example

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 21: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Compound operations

Opening: geometrical interpretation

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 22: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Compound operations

Closing: dilation followed by erosion

Mathematically:

In MATLAB: imclose (Tutorial 13.1)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 23: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Compound operations

Closing: example

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 24: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Compound operations

Closing: geometrical interpretation

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 25: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Compound operations

Hit-or-miss (HoM) transform: a combination of morphological operations that uses two structuring elements (B1 and B2) designed in such a way that the output image will consist of all locations that match the pixels in B1 (a hit) and that have none of the pixels in B2 (a miss).

Mathematically:

or:

In MATLAB: bwhitmiss (Tutorial 13.1)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 26: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Compound operations

HoM: example (Fig. 13.10)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 27: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Morphological filtering

Morphological filters are Boolean filters that apply a many-to-one binary (or Boolean) function h within a window W in the binary input image f(x,y), producing at the output an image g(x,y) given by:

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 28: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Morphological filtering

Examples of Boolean operations (h):

OR: equivalent to a morphological dilation with a square SE of the same size as W.

AND: equivalent to a morphological erosion with a square SE of the same size as W.

MAJ (majority): the morphological equivalent to a median filter applicable to binary images.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 29: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Morphological filtering Application: noise removal

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 30: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Morphological algorithms

A “cookbook” approach

In MATLAB: bwmorph (see also Tutorial 13.2)

Example 13.6:

A = imread('circles.png');

B = bwmorph(A,'skel', Inf);

C = bwmorph(B,'spur',Inf);

D = bwmorph(A,'remove');

E = bwmorph(D,'thicken',3);

F = bwmorph(E,'thin',3);

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 31: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Morphological algorithms

Example 13.6:

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 32: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Morphological algorithms

Operations supported by bwmorph

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 33: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Boundary extraction

Internal: pixels in A that sit at the edge of A.

External: pixels outside A that sit immediately next to A.

Morphological gradient: combination of internal and external boundaries.

In MATLAB: bwperim

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 34: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Boundary extraction

Example 13.7:

a = ones(5,12)

a (1:2,1)=0

a (1:2,9)=0

a (4:5,5)=0

b = bwperim(a,8)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 35: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Region filling

In MATLAB: imfill

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 36: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Region filling

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 37: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Extraction and labeling of connected components Iterative procedure, similar to region filling

In MATLAB: bwlabel, bwselect, label2rgb

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 38: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Extraction and labeling of connected components

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 39: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Grayscale morphology

Many morphological operations originally developed for binary images can be extended to grayscale images.

The mathematical formulation of grayscale morphology uses an input image f(x,y) and a structuring element (SE) b(x,y). Structuring elements in grayscale morphology come

in two categories: nonflat and flat.

In MATLAB: strel Nonflat SEs can be created with the same function

used to create flat SEs, but we must also pass a second matrix (containing the height values) as a parameter.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 40: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Grayscale morphology

Dilation

The dilation of an image f(x,y) by a flat SE b(x,y) is defined as:

where Db is called the domain of b.

For a nonflat SE, bN(x,y):

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 41: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Grayscale morphology

Erosion

The erosion of an image f(x,y) by a flat SE b(x,y) is defined as:

where Db is called the domain of b.

For a nonflat SE, bN(x,y):

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 42: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Grayscale erosion and dilation

Example 13.8

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 43: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Grayscale morphology

Opening

The opening of an image f(x,y) by SE b(x,y) is given by:

Closing

The closing of an image f(x,y) by SE b(x,y) is given by:

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 44: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Grayscale opening and closing

Example 13.9

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 45: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Grayscale morphology

Top-hat transformation

Bottom-hat transformation

In MATLAB: imtophat and imbothat

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 46: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Top-hat and bottom-hat

Example 13.10

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 47: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

Hands-on

Tutorial 13.1: Binary morphological image processing (page 325)

Tutorial 13.2: Basic morphological algorithms (page 330)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 48: Practical Image and Video Processing Using …instructor.sdu.edu.kz/~konst/cv2013/lectures/lecture10...image processing? What are the main morphological operations and what is the

References

Practical Image and Video Processing Using MATLAB®, Oge Marques, Chapter 13

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.