1 template matching roland miezianko assignment 2 cis 581 october 30, 2002

21
1 Template Matching Template Matching Roland Miezianko Roland Miezianko Assignment 2 Assignment 2 CIS 581 CIS 581 October 30, 2002 October 30, 2002

Upload: georgia-ray

Post on 14-Jan-2016

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

1

Template MatchingTemplate Matching

Roland MieziankoRoland Miezianko

Assignment 2Assignment 2

CIS 581CIS 581

October 30, 2002October 30, 2002

Page 2: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

2

AgendaAgenda

• Template MatchingTemplate Matching– Definition and MethodDefinition and Method– Bi-Level ImageBi-Level Image– Gray-Level ImageGray-Level Image

• Matlab ExampleMatlab Example– Gray-Level Template MatchingGray-Level Template Matching– Machine Vision ExampleMachine Vision Example

Page 3: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

3

DefinitionDefinition

• Technique used in classifying Technique used in classifying objects.objects.

• Template Matching techniques Template Matching techniques compare portions of images compare portions of images against one another.against one another.

• Sample image may be used to Sample image may be used to recognize similar objects in source recognize similar objects in source image.image.

Page 4: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

4

Definition, cont.Definition, cont.

• If standard deviation of the If standard deviation of the template image compared to the template image compared to the source image is small enough, source image is small enough, template matching may be used.template matching may be used.

• Templates are most often used to Templates are most often used to identify printed characters, identify printed characters, numbers, and other small, simple numbers, and other small, simple objects.objects.

Page 5: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

5

MethodMethod

x,y

Template Image

Input Image

I(x,y) O(x,y)

Output Image

x,yCorrelation

The matching process moves the template image to all possible positions in a larger source image and computes a numerical index that indicates how well the template matches the image in that position.

Match is done on a pixel-by-pixel basis.

Page 6: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

6

CorrelationCorrelation

• CorrelationCorrelation is a measure of the is a measure of the degree to which two variables degree to which two variables agree, not necessary in actual agree, not necessary in actual value but in general behavior.value but in general behavior.

• The two variables are the The two variables are the corresponding pixel values in two corresponding pixel values in two images, template and source.images, template and source.

Page 7: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

7

Bi-Level Image TMBi-Level Image TM

• Template is a small image, usually Template is a small image, usually a bi-level image.a bi-level image.

• Find template in source image, Find template in source image, with a Yes/No approach.with a Yes/No approach.

Template Source

Page 8: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

8

Grey-Level Image TMGrey-Level Image TM

• When using template-matching scheme on When using template-matching scheme on grey-level image it is unreasonable to expect a grey-level image it is unreasonable to expect a perfect match of the grey levels.perfect match of the grey levels.

• Instead of yes/no match at each pixel, the Instead of yes/no match at each pixel, the difference in level should be used.difference in level should be used.

Template Source Image

Page 9: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

9

Grey-LevelGrey-LevelCorrelation FormulaCorrelation Formula

1

0

1

0

22

1

0)(

N

i

N

iii

i

N

i i

yyxx

yyxxr

x is the template gray level image

x is the average grey level in the template image

y is the source image section

y is the average grey level in the source image

N is the number of pixels in the section image (section image == template image size) columns * rows

The value r is between –1 and +1, with larger values representing a stronger relationship between the two images.

Page 10: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

10

Correlation is Computation Correlation is Computation IntensiveIntensive

• Template image size: 53 x 48Template image size: 53 x 48• Source image size: 177 x 236Source image size: 177 x 236• Assumption: template image is inside Assumption: template image is inside

the source image.the source image.• Correlation (search) matrix size: 124 x Correlation (search) matrix size: 124 x

188 (177-53 x 236-48)188 (177-53 x 236-48)

• Computation countComputation count124 x 188 x 53 x 48 = 59,305,728124 x 188 x 53 x 48 = 59,305,728

Page 11: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

11

Machine Vision ExampleMachine Vision Example

• Load printed circuit board Load printed circuit board into a machineinto a machine

• Teach template image Teach template image (select and store)(select and store)

• Load printed circuit boardLoad printed circuit board• Capture a source image Capture a source image

and find templateand find template

Page 12: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

12

Machine Vision ExampleMachine Vision Example

Assumptions and Limitations

1. Template is entirely located in source image

2. Partial template matching was not performed (at boundaries, within image)

3. Rotation and scaling will cause poor matches

Page 13: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

13

Matlab ExampleMatlab Example

TemplateData Set 1 Data Set 2

Data Set 3 Data Set 4 Data Set 5

Matlab Data SetMatlab Data Set

Page 14: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

14

Data Set 1Data Set 1

Correlation Map with Peak Source Image, Found Rectangle, and Correlation Map

Page 15: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

15

Data Set 2Data Set 2

Correlation Map with Peak Source Image and Found Rectangle

Page 16: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

16

Data Set 3Data Set 3

Correlation Map with Peak Source Image and Found Rectangle

Page 17: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

17

Data Set 4Data Set 4

Correlation Map with Peak Source Image and Found Rectangle

Page 18: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

18

Data Set 5, Corr. MapData Set 5, Corr. Map

Correlation Map with Peak Source Image

Page 19: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

19

Data Set 5, ResultsData Set 5, Results

Threshold set to 0.800 Threshold set to 0.200

Page 20: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

20

Matlab and Data FilesMatlab and Data Files

Matlab Files

hw2.m findTemplate.m hw2output.m

Data and Output Files

F06Temp.bmp F08.BMP CircleTemplate.bmp F08CorrMap.bmp F01.BMP F08CorrMap.txt

F01CorrMap.bmp F08Temp.bmp F01CorrMap.txt

PAD1.BMP F01Temp.bmp PAD1CorrMap.bmp

F01TempContour.bmp PAD1CorrMap.txt F05.BMP PAD1TempN.bmp F05CorrMap.bmp PAD1TempY.bmp

F05CorrMap.txt F05Temp.bmp F06.BMP

F06CorrMap.bmp F06CorrMap.txt

Page 21: 1 Template Matching Roland Miezianko Assignment 2 CIS 581 October 30, 2002

21

QuestionsQuestionsandand

AnswersAnswers