Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

56
Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    229
  • download

    6

Transcript of Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Page 1: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Introduction to Computer Vision

Lecture 16

Dr. Roger S. Gaborski

Page 2: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 2

Binary Morphological Processing

• Non-linear image processing technique– Order of sequence of operations is important

• Linear: (3+2)*3 = (5)*3=153*3+2*3=9+6=15

• Non-linear: (3+2)2 + (5)2 =25 [sum, then square] (3)2 + (2)2 =9+4=13 [square, then sum]

• Based on geometric structure• Used for edge detection, noise removal and

feature extraction Used to ‘understand’ the shape/form of a

binary image

Page 3: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 3

Image – Set of Pixels

• Basic idea is to treat an object within an image as a set of pixels (or coordinates of pixels)

• In binary images, pixels that are ‘off’, set to 0, are background and appear black. Foreground pixels (objects) are 1 and appear white

Page 4: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 4

Neighborhood

• Set of pixels defined by their location relation to the pixel of interest– Defined by structuring element– Specified by connectivity

• Connectivity- – ‘4-connected’ – ‘8-connected’

Page 5: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 5

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 6: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 6

Translation of Object A by vector b

• Define Translation ob object A by vector b:At = { t I2 : t = a+b, a A }

Where I2 is the two dimensional image space that contains the image

• Definition of DILATION is the UNION of all the translations:

A B = { t I2 : t = a+b, a A } for all b’s in B

Page 7: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 7

DILATION

Object B is one point located at (a,0) A1: Object A is translated by object BSince dilation is the union of all the translations, A B = At where the set union is for all the b’s in B, the dilation of rectangle A in the positive x direction by a results in rectangle A1 (same size as A, just translated to the right)

A1A

Page 8: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 8

DILATION – B has 2 Elements

Object B is 2 points, (a,0), (-a,0) There are two translations of A as result of two elements in BDilation is defined as the UNION of the objectsA1 and A2. NOT THE INTERSECTION

A2 A1(part of A1 is under A2)

A

-a a -a a

Page 9: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 9

DILATIONRounded corners

Round Structuring Element (SE) can be interpretedas rolling the SE around the contour of the object.New object has rounded corners and is larger by½ width of the SE

Page 10: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 10

DILATIONRounded corners

Square Structuring Element (SE) can be interpretedas moving the SE around the contour of the object.New object has square corners and is larger by½ width of the SE

Page 11: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 11

DILATION

• The shape of B determines the final shape of the dilated object. B acts as a geometric filter that changes the geometric structure of A

Page 12: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 12

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 13: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 13

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 14: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 14

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 15: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 15

imdilate

IM2 = IMDILATE(IM,NHOOD) dilates the image IM, where NHOOD is a matrix of 0s and 1s that specifies the structuring element neighborhood. This is equivalent to the syntax IIMDILATE(IM, STREL(NHOOD)). IMDILATE determines the center element of the neighborhood by FLOOR((SIZE(NHOOD) + 1)/2).

>> se = imrotate(eye(3),90)se =

0 0 1 0 1 0 1 0 0

>> ctr=floor(size(se)+1)/2ctr = 2 2

Page 16: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 16

>> I = zeros([13 19]);>> I(6,6:8)=1;>> I2 = imdilate(I,se);

0.5 1 1.5 2 2.5 3 3.5

0.5

1

1.5

2

2.5

3

3.5

2 4 6 8 10 12 14 16 18

2

4

6

8

10

12

2 4 6 8 10 12 14 16 18

2

4

6

8

10

12

Page 17: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 17

MATLAB Dilation Example

>> I = zeros([13 19]);>> I(6, 6:12)=1;>> SE = imrotate(eye(5),90);>> I2=imdilate(I,SE);>> figure, imagesc(I)>> figure, imagesc(SE)>> figure, imagesc(I2)

Page 18: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 18

SE

DILATED IMAGEINPUT IMAGE

Page 19: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 19

>> I(6:9,6:13)=1;>> figure, imagesc(I)>> I2=imdilate(I,SE);>> figure, imagesc(I2)

I I2

SE

Page 20: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 20

SE =

1 1 1 1 1 1 1 1 1

I I2

Page 21: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 21

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 22: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 22

Dilation and Erosion

• DILATION: Adds pixels to the boundary of an object

• EROSIN: Removes pixels from the boundary of an object

• Number of pixels added or removed depends on size and shape of structuring element

Page 23: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 23

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 24: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 24

MATLAB Erosion Example

I3=imerode(I2,SE);

2 pixelwide

SE = 3x3

Page 25: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 25

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 26: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 26

Combinations

• In most morphological applications dilation and erosion are used in combination

• May use same or different structuring elements

Page 27: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 27

Morphological Opening and Closing

• Opening of A by B A BErosion of A by B, followed bythe dilation of the result by B

Closing of A by B A B Dilation of A by B, followed bythe erosion of the result by B

MATLAB: imopen(A, B) imclose(A,B)

Page 28: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 28

MATLAB Function strel

• strel constructs structuring elements with various shapes and sizes

• Syntax: se = strel(shape, parameters)

• Example:– se = strel(‘octagon’, R);– R is the dimension – see help function

Page 29: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 29

• Opening of A by B A BErosion of A by B, followed by the dilation of the result by B

Erosion- if any element of structuring element overlaps with background output is zero

FIRST - EROSION

>> se = strel('square', 20);fe = imerode(f,se);figure, imagesc(fe),title('fe')

Page 30: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 30

Dilation of Previous ResultOutputs 1 at center of SE when at least one element of SE overlaps object

SECOND - DILATION

>> se = strel('square', 20);fd = imdilate(fe,se);figure, imagesc(fd),title('fd')

Page 31: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 31

FO=imopen(f,se); figure, imagesc(FO),title('FO')

Page 32: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 32

What if we increased size of SE for DILATION operation??

se = strel('square', 25);fd = imdilate(fe,se);figure, imagesc(fd),title('fd')se = strel('square', 30);fd = imdilate(fe,se);figure, imagesc(fd),title('fd')

se = 25 se = 30

Page 33: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 33

Closing of A by B A B Dilation of A by B

se = strel('square', 20);fd = imdilate(f,se);figure, imagesc(fd),title('fd')

Outputs 1 at center of SE when at least one element of SE overlaps object

Page 34: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 34

Erosion of the result by B

Erosion- if any element of structuring element overlaps with background output is zero

Page 35: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 35

ORIGINAL

OPENING CLOSING

Page 36: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 36

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 37: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 37

Hit or Miss Transformation

• Useful to identify specified configuration of pixels, such as, isolated foreground pixels or pixels at end of lines (end points)

• A B = (A B1) (Ac B2)• A eroded by B1, intersection A

complement eroded by B2 (two different structuring elements)

Page 38: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 38

Hit or Miss Example

• Find cross shape pixel configuration:

0 1 0

1 1 1

0 1 0

MATLAB Function: C = bwhitmiss(A, B1, B2)

Page 39: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 39

Original Image A and B1

A eroded by B1

Complement of OriginalImage and B2

Erosion of A complementAnd B2

Intersection of eroded images

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 40: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 40

Hit or Miss

• Have all the pixels in B1, but none of the pixels in B2

Page 41: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 41

Hit or Miss Example #2

• Locate upper left hand corner pixels of objects in an image

• Pixels that have east and south neighbors (Hits) and no NE, N, NW, W, SW Pixels (Misses)

B1 = B2 = 0 0 0

0 1 1

0 1 0

1 1 1

1 0 0

1 0 0

Don’tCare aboutSE

Page 42: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 42

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

G = bwhitmiss(f, B1, B2);Figure, imshow(g)

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 43: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 43

bwmorph(f, operation, n)

• Implements various morphological operations based on combinations of dilations, erosions and look up table operations.

• Example: Thinning>> f = imread(‘fingerprint_cleaned.tif’);

>> g = bwmorph(f, ‘thin’, 1);

>> g2 = bwmorph(f, ‘thin’, 2);

>> g3 = bwmorph(f, ‘thin’, Inf);

Page 44: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 44

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

Input

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 45: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 45

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 46: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 46

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 47: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 47

Labeling Connected Components

• Label objects in an image

• 4-Neighbors

• 8-Neighbors

p p

Page 48: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 48

4 and 8 Connect

Input Image 8 – Connect 4 - Connect

Page 49: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 49

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 50: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 50

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 51: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 51

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 52: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 52

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 53: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 53

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 54: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 54

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins

Page 55: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 55

Reflection

• Dilation definition:

“Dilation of A by B is the set consisting of all structuring element origin locations where the reflected and translated B overlaps at least some portion of A”

• If structuring element is symmetric with respect to origin, reflection of B has no effect

Page 56: Introduction to Computer Vision Lecture 16 Dr. Roger S. Gaborski.

Roger S. Gaborski 56

Chapter 9Morphological Image Processing

Chapter 9Morphological Image Processing

From: Digital Image Processing, Gonzalez,Woods And Eddins