SlideShare a Scribd company logo
1 of 20
Template Matching

         Longin Jan Latecki

          Temple University
               CIS 601
Based on a project by Roland Miezianko

                                         1
Agenda
• Template Matching
 – Definition and Method
 – Bi-Level Image
 – Gray-Level Image
• Matlab Example
 – Gray-Level Template Matching
 – Machine Vision Example

                           2
Definition
• Technique used in classifying
  objects.
• Template Matching techniques
  compare portions of images
  against one another.
• Sample image may be used to
  recognize similar objects in
  source image.

                         3
Definition, cont.
• If standard deviation of the
  template image compared to the
  source image is small enough,
  template matching may be used.
• Templates are most often used
  to identify printed characters,
  numbers, and other small,
  simple objects.
                         4
Method

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



           Template Image




     Input Image                                            Output Image

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.

                                                                   5
Bi-Level Image TM
• Template is a small image,
  usually a bi-level image.
• Find template in source image,
  with a Yes/No approach.




      Template     Source

                             6
Grey-Level Image TM
• When using template-matching scheme on
  grey-level image it is unreasonable to
  expect a perfect match of the grey levels.
• Instead of yes/no match at each pixel, the
  difference in level should be used.



  Template                        Source Image




                                   7
Euclidean Distance

Let I be a gray level image
and g be a gray-value template of size n×m.


                        n   m                                2

d ( I , g , r , c) =   ∑∑ ( I (r + i, c + j ) − g (i, j ))
                       i =1 j =1




In this formula (r,c) denotes the top left corner of template g.

                                                                 8
Correlation
• Correlation is a measure of the
  degree to which two variables
  agree, not necessary in actual
  value but in general behavior.
• The two variables are the
  corresponding pixel values in
  two images, template and
  source.
                         9
Grey-Level
Correlation Formula

                      ∑               ( xi − x ) ⋅ ( yi − y )
                             N −1

 cor =                       i =0
                     N −1                            N −1

                     ∑( x             − x ) ⋅ ∑( yi − y )
                                               2                              2
                                 i
                     i =0                            i =0
 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
 (N= template image size = columns * rows)
 The value cor is between –1 and +1,
                                                                           10
 with larger values representing a stronger relationship between the two images.
Correlation is
Computation Intensive
• Template image size: 53 x 48
• Source image size: 177 x 236
• Assumption: template image is inside
  the source image.
• Correlation (search) matrix size: 124
  x 188 (177-53 x 236-48)

• Computation count
    124 x 188 x 53 x 48 = 59,305,728
                                       11
Machine Vision Example
• Load printed circuit
  board into a machine
• Teach template image
  (select and store)
• Load printed circuit
  board
• Capture a source
  image and find
  template


                         12
Machine 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          13
Matlab Example
Matlab Data Set



      Template
                   Data Set 1   Data Set 2




      Data Set 3   Data Set 4    Data Set 5



                                     14
Data Set 1




Correlation Map with Peak   Source Image, Found
                            Rectangle, and Correlation
                            Map
                                            15
Data Set 2




Correlation Map with Peak   Source Image and Found
                            Rectangle

                                          16
Data Set 3




Correlation Map with Peak   Source Image and Found
                            Rectangle

                                          17
Data Set 4




Correlation Map with Peak   Source Image and Found
                            Rectangle

                                          18
Data Set 5, Corr. Map




Correlation Map with Peak   Source Image

                                   19
Data Set 5, Results




Threshold set to 0.800   Threshold set to 0.200


                                        20

More Related Content

What's hot

Digital Image restoration
Digital Image restorationDigital Image restoration
Digital Image restorationMd Shabir Alam
 
Image segmentation
Image segmentationImage segmentation
Image segmentationkhyati gupta
 
Fundamentals and image compression models
Fundamentals and image compression modelsFundamentals and image compression models
Fundamentals and image compression modelslavanya marichamy
 
Digital image processing
Digital image processingDigital image processing
Digital image processingAstha Jain
 
Introduction to Digital Image Processing
Introduction to Digital Image ProcessingIntroduction to Digital Image Processing
Introduction to Digital Image Processingkalaimuthu2
 
Digital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image FundamentalsDigital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image FundamentalsMostafa G. M. Mostafa
 
Color Image Processing
Color Image ProcessingColor Image Processing
Color Image Processingkiruthiammu
 
filters for noise in image processing
filters for noise in image processingfilters for noise in image processing
filters for noise in image processingSardar Alam
 
Image Enhancement
Image Enhancement Image Enhancement
Image Enhancement Deven Sahu
 
Image Registration (Digital Image Processing)
Image Registration (Digital Image Processing)Image Registration (Digital Image Processing)
Image Registration (Digital Image Processing)VARUN KUMAR
 
Simultaneous Smoothing and Sharpening of Color Images
Simultaneous Smoothing and Sharpening of Color ImagesSimultaneous Smoothing and Sharpening of Color Images
Simultaneous Smoothing and Sharpening of Color ImagesCristina Pérez Benito
 
Image processing fundamentals
Image processing fundamentalsImage processing fundamentals
Image processing fundamentalsA B Shinde
 
Watershed Segmentation Image Processing
Watershed Segmentation Image ProcessingWatershed Segmentation Image Processing
Watershed Segmentation Image ProcessingArshad Hussain
 
introduction to Digital Image Processing
introduction to Digital Image Processingintroduction to Digital Image Processing
introduction to Digital Image Processingnikesh gadare
 
Enhancement in frequency domain
Enhancement in frequency domainEnhancement in frequency domain
Enhancement in frequency domainAshish Kumar
 
Image Processing Basics
Image Processing BasicsImage Processing Basics
Image Processing BasicsA B Shinde
 

What's hot (20)

image compression ppt
image compression pptimage compression ppt
image compression ppt
 
Ppt ---image processing
Ppt ---image processingPpt ---image processing
Ppt ---image processing
 
Digital Image restoration
Digital Image restorationDigital Image restoration
Digital Image restoration
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Fundamentals and image compression models
Fundamentals and image compression modelsFundamentals and image compression models
Fundamentals and image compression models
 
Image restoration and reconstruction
Image restoration and reconstructionImage restoration and reconstruction
Image restoration and reconstruction
 
Digital image processing
Digital image processingDigital image processing
Digital image processing
 
Introduction to Digital Image Processing
Introduction to Digital Image ProcessingIntroduction to Digital Image Processing
Introduction to Digital Image Processing
 
Digital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image FundamentalsDigital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image Fundamentals
 
Color Image Processing
Color Image ProcessingColor Image Processing
Color Image Processing
 
filters for noise in image processing
filters for noise in image processingfilters for noise in image processing
filters for noise in image processing
 
Image Enhancement
Image Enhancement Image Enhancement
Image Enhancement
 
Image Registration (Digital Image Processing)
Image Registration (Digital Image Processing)Image Registration (Digital Image Processing)
Image Registration (Digital Image Processing)
 
Simultaneous Smoothing and Sharpening of Color Images
Simultaneous Smoothing and Sharpening of Color ImagesSimultaneous Smoothing and Sharpening of Color Images
Simultaneous Smoothing and Sharpening of Color Images
 
Image processing fundamentals
Image processing fundamentalsImage processing fundamentals
Image processing fundamentals
 
Watershed Segmentation Image Processing
Watershed Segmentation Image ProcessingWatershed Segmentation Image Processing
Watershed Segmentation Image Processing
 
introduction to Digital Image Processing
introduction to Digital Image Processingintroduction to Digital Image Processing
introduction to Digital Image Processing
 
Enhancement in frequency domain
Enhancement in frequency domainEnhancement in frequency domain
Enhancement in frequency domain
 
Spatial filtering
Spatial filteringSpatial filtering
Spatial filtering
 
Image Processing Basics
Image Processing BasicsImage Processing Basics
Image Processing Basics
 

Similar to Template matching03

MLIP - Chapter 6 - Generation, Super-Resolution, Style transfer
MLIP - Chapter 6 - Generation, Super-Resolution, Style transferMLIP - Chapter 6 - Generation, Super-Resolution, Style transfer
MLIP - Chapter 6 - Generation, Super-Resolution, Style transferCharles Deledalle
 
Surface Data Capture Image Matching
Surface Data Capture Image MatchingSurface Data Capture Image Matching
Surface Data Capture Image MatchingRASHID JAVED
 
Template Matching - Pattern Recognition
Template Matching - Pattern RecognitionTemplate Matching - Pattern Recognition
Template Matching - Pattern RecognitionMustafa Salam
 
Based on correlation coefficient in image matching
Based on correlation coefficient in image matchingBased on correlation coefficient in image matching
Based on correlation coefficient in image matchingIJRES Journal
 
Week06 bme429-cbir
Week06 bme429-cbirWeek06 bme429-cbir
Week06 bme429-cbirIkram Moalla
 
A hybrid genetic algorithm and chaotic function model for image encryption
A hybrid genetic algorithm and chaotic function model for image encryptionA hybrid genetic algorithm and chaotic function model for image encryption
A hybrid genetic algorithm and chaotic function model for image encryptionsadique_ghitm
 
202224010101 RAHMAN SHIDDIQUR - Image Stitching.pptx
202224010101 RAHMAN SHIDDIQUR - Image Stitching.pptx202224010101 RAHMAN SHIDDIQUR - Image Stitching.pptx
202224010101 RAHMAN SHIDDIQUR - Image Stitching.pptxKazmirFahrier
 
Image enhancement in the spatial domain1
Image enhancement in the spatial domain1Image enhancement in the spatial domain1
Image enhancement in the spatial domain1shabanam tamboli
 
Image Enhancement in the Spatial Domain1.ppt
Image Enhancement in the Spatial Domain1.pptImage Enhancement in the Spatial Domain1.ppt
Image Enhancement in the Spatial Domain1.pptShabanamTamboli1
 
Realism of image composits
Realism of image compositsRealism of image composits
Realism of image compositsAliya Ibragimova
 
Dip digital image 3
Dip digital image 3Dip digital image 3
Dip digital image 3Shajun Nisha
 
Comparison of image segmentation
Comparison of image segmentationComparison of image segmentation
Comparison of image segmentationHaitham Ahmed
 
Matlab intro
Matlab introMatlab intro
Matlab introfvijayami
 
Lec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdfLec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdfnagwaAboElenein
 

Similar to Template matching03 (20)

MLIP - Chapter 6 - Generation, Super-Resolution, Style transfer
MLIP - Chapter 6 - Generation, Super-Resolution, Style transferMLIP - Chapter 6 - Generation, Super-Resolution, Style transfer
MLIP - Chapter 6 - Generation, Super-Resolution, Style transfer
 
Surface Data Capture Image Matching
Surface Data Capture Image MatchingSurface Data Capture Image Matching
Surface Data Capture Image Matching
 
Template Matching - Pattern Recognition
Template Matching - Pattern RecognitionTemplate Matching - Pattern Recognition
Template Matching - Pattern Recognition
 
regions
regionsregions
regions
 
Based on correlation coefficient in image matching
Based on correlation coefficient in image matchingBased on correlation coefficient in image matching
Based on correlation coefficient in image matching
 
Dip day1&2
Dip day1&2Dip day1&2
Dip day1&2
 
Week06 bme429-cbir
Week06 bme429-cbirWeek06 bme429-cbir
Week06 bme429-cbir
 
A hybrid genetic algorithm and chaotic function model for image encryption
A hybrid genetic algorithm and chaotic function model for image encryptionA hybrid genetic algorithm and chaotic function model for image encryption
A hybrid genetic algorithm and chaotic function model for image encryption
 
2. IP Fundamentals.pdf
2. IP Fundamentals.pdf2. IP Fundamentals.pdf
2. IP Fundamentals.pdf
 
202224010101 RAHMAN SHIDDIQUR - Image Stitching.pptx
202224010101 RAHMAN SHIDDIQUR - Image Stitching.pptx202224010101 RAHMAN SHIDDIQUR - Image Stitching.pptx
202224010101 RAHMAN SHIDDIQUR - Image Stitching.pptx
 
Image enhancement in the spatial domain1
Image enhancement in the spatial domain1Image enhancement in the spatial domain1
Image enhancement in the spatial domain1
 
Image Enhancement in the Spatial Domain1.ppt
Image Enhancement in the Spatial Domain1.pptImage Enhancement in the Spatial Domain1.ppt
Image Enhancement in the Spatial Domain1.ppt
 
Realism of image composits
Realism of image compositsRealism of image composits
Realism of image composits
 
Pca analysis
Pca analysisPca analysis
Pca analysis
 
Dip digital image 3
Dip digital image 3Dip digital image 3
Dip digital image 3
 
Template Matching
Template MatchingTemplate Matching
Template Matching
 
Comparison of image segmentation
Comparison of image segmentationComparison of image segmentation
Comparison of image segmentation
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
poster
posterposter
poster
 
Lec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdfLec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdf
 

Recently uploaded

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Recently uploaded (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Template matching03

  • 1. Template Matching Longin Jan Latecki Temple University CIS 601 Based on a project by Roland Miezianko 1
  • 2. Agenda • Template Matching – Definition and Method – Bi-Level Image – Gray-Level Image • Matlab Example – Gray-Level Template Matching – Machine Vision Example 2
  • 3. Definition • Technique used in classifying objects. • Template Matching techniques compare portions of images against one another. • Sample image may be used to recognize similar objects in source image. 3
  • 4. Definition, cont. • If standard deviation of the template image compared to the source image is small enough, template matching may be used. • Templates are most often used to identify printed characters, numbers, and other small, simple objects. 4
  • 5. Method I(x,y) O(x,y) Correlation x,y x,y Template Image Input Image Output Image 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. 5
  • 6. Bi-Level Image TM • Template is a small image, usually a bi-level image. • Find template in source image, with a Yes/No approach. Template Source 6
  • 7. Grey-Level Image TM • When using template-matching scheme on grey-level image it is unreasonable to expect a perfect match of the grey levels. • Instead of yes/no match at each pixel, the difference in level should be used. Template Source Image 7
  • 8. Euclidean Distance Let I be a gray level image and g be a gray-value template of size n×m. n m 2 d ( I , g , r , c) = ∑∑ ( I (r + i, c + j ) − g (i, j )) i =1 j =1 In this formula (r,c) denotes the top left corner of template g. 8
  • 9. Correlation • Correlation is a measure of the degree to which two variables agree, not necessary in actual value but in general behavior. • The two variables are the corresponding pixel values in two images, template and source. 9
  • 10. Grey-Level Correlation Formula ∑ ( xi − x ) ⋅ ( yi − y ) N −1 cor = i =0 N −1 N −1 ∑( x − x ) ⋅ ∑( yi − y ) 2 2 i i =0 i =0 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 (N= template image size = columns * rows) The value cor is between –1 and +1, 10 with larger values representing a stronger relationship between the two images.
  • 11. Correlation is Computation Intensive • Template image size: 53 x 48 • Source image size: 177 x 236 • Assumption: template image is inside the source image. • Correlation (search) matrix size: 124 x 188 (177-53 x 236-48) • Computation count 124 x 188 x 53 x 48 = 59,305,728 11
  • 12. Machine Vision Example • Load printed circuit board into a machine • Teach template image (select and store) • Load printed circuit board • Capture a source image and find template 12
  • 13. Machine 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 13
  • 14. Matlab Example Matlab Data Set Template Data Set 1 Data Set 2 Data Set 3 Data Set 4 Data Set 5 14
  • 15. Data Set 1 Correlation Map with Peak Source Image, Found Rectangle, and Correlation Map 15
  • 16. Data Set 2 Correlation Map with Peak Source Image and Found Rectangle 16
  • 17. Data Set 3 Correlation Map with Peak Source Image and Found Rectangle 17
  • 18. Data Set 4 Correlation Map with Peak Source Image and Found Rectangle 18
  • 19. Data Set 5, Corr. Map Correlation Map with Peak Source Image 19
  • 20. Data Set 5, Results Threshold set to 0.800 Threshold set to 0.200 20