%Point matching test algorithm 
%Longin Jan Latecki, latecki@temple.edu, November 2012 

%the toy example for matching 7 points to 6 points called labels
%A is matrix of pairwise affinites of pairs (point, label)
%M is mutex matrix on pairs (point, label)
close all
clear all
points = [0 0; 1 1; 0 1; 0 2; 0 3; 2 2; 3 3];
labels = points + 0.1*randn(7,2); %points plus noise
labels(7,:)=[]; 
trueCorr=[1 2 3 4 5 6 0];
npoints=length(points);
nlabels=length(labels);
%shows the configuration of points in blue and labels in red
figure; plot(points(:,1),points(:,2),'k*','MarkerSize',14);
for i=1:length(points)
    text(points(i,1)+0.05,points(i,2)+0.1,num2str(i));
end
hold on; axis equal;
plot(labels(:,1),labels(:,2),'r^','MarkerSize',14); 
title('point configuration');

labels = labels + rand*7; %we shift the label points

%calling the matching function
[C]=pointmatchfun(points,labels,1);

%computes the matching accuracy
matchingaccuracy= sum(C==trueCorr)/length(trueCorr)


 %vizualization
CorrProb=zeros(npoints,nlabels);
for i=1:length(C)
    if C(i) <= nlabels && C(i) > 0
        CorrProb(i,C(i))=1;
    end
end
figure; imagesc(CorrProb); title('corr by pointmatchfun');

