Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

MCT-453: Machine Vision

Template Matching Technique for Object Detection


Lab Session 7
Objective:
Simple object detection by implementing template matching technique using
normalized cross correlation on input image and given template.

Problem Definition:

Suppose that you are a manager Quality Control Cell at a circuit board
manufacturing company. One of your responsibilities is to ensure your
subordinates checks the presence of all the IC components on one thousand boards
daily. But this process is laborious and your employee turnover rate is very high
and it results in lower production.

Luckily, you have learned in Machine Vision-453 that cross-correlation can be


used for template matching: a template is multiplied with regions of a larger
image to measure how similar each region is to the template. The template of an IC
(temp.jpg) and the image of board (circuit.jpg) is provided. We will use cross-
correlation to find the ICs in the board.

Activity 01: Template Matching:


Write a function(circuit1, temp1) to
 First read an input image (circuit1) and given template image (temp1).
 Apply gray conversion on both images
 Apply Normalized Cross Correlation (normxcorr2) between both images to
detect all instance of template image in input image
 Visualize result of above step using 3D function surf (c)
 Apply local maxima function and some thresholding value to detect only
peaks where correlation has maximum value
 Draw input image along with bounding boxes of template size at each object
location
 Display the total number of template objects found on title of figure.
Result:

Useful Functions:
normxcorr2( Img, tempI ); surf (c); imrect (gca, [x,y ,x1, y1]); findpeaks ()

Video Demo: https://youtu.be/C3o5qhDgR6o

You might also like