Matlab Code for Template Matching

The comparison of two images is done based on correlation coefficient. The quantitative measure of the degree of association of two distinct variables is often coined as correlation coefficient, which typically ranges between -1 and 1.


Pearson Correlation coefficient,
Let’s start with the basics.

Steps to be performed for finding the correlation coefficient between two vectors or matrices.

This denotes that the matrix A and B are highly correlated.

MATLAB CODE:

Example: 1

A= [1 4 7; 2 5 8; 3 6 9]
B = A*2

%Find the average of the matrix A
meanA = mean2(A);

%Find the average of the matrix B
meanB = mean2(B);

%Subtract the average value from matrix A
Asub = A-meanA;

%Subtract the average value from matrix B
Bsub = B-meanB;

%Covariance of matrix A and matrix B
covAB = mean2(Asub.*Bsub);

%Find the standard deviation of the matrix A
stdA = std(A(:),1);

%Find the standard deviation of the matrix B
stdB = std(B(:),1);

%Find the correlation Cofficient
Rho = covAB./(stdA*stdB)


Example: 2

%Assign new values to B
B = [9 6 3;8 5 2; 7 4 1];

Rho = corr2(A,B)


Contact:
Mr. Roshan P. Helonde
Mobile: +91-7276355704
WhatsApp: +91-7276355704
Email: roshanphelonde@rediffmail.com
Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *