function [ Corr ] = pointmatchfun( points,labels,maxpoints )
plength=length(points);
llength=length(labels);

distance=ones(plength,llength);

for uuc=1:plength
    for yukari=1:llength
        distance(uuc,yukari)=abs((points(uuc,1)-labels(yukari,1))+(points(uuc,2)-labels(yukari,2)));
    end
end

for uuc=2:maxpoint
    distance=[distance distance]
end

[p l]=size(distance);

if p>l
    distance=[distance 99*ones(p,l-p)];
    
elseif l>p
    distance=[distance;99*ones(l-p,l)];
end

slength=max(p,l);

for uuc=1:slength
    distance(uuc,:)=distance(uuc,:)-min(distance(uuc,:));
end

for uuc=1:slength
    distance(:,uuc)=distance(:,uuc)-min(distance(:,uuc));
end

[rows cols count]=cover(distance,slength);


while count~=slength
    %step 6
    hmin=999;
    for uuc=1:slength
        for yukari=1:slength
            if rows(uuc,1)~=1 && cols(yukari,1)~=1 && distance(uuc,yukari)<hmin
                hmin=distance(uuc,yukari);
            end
        end
    end
    
   
    for uuc=1:slength
        if rows(uuc,1)==1
            for yukari=1:slength
                distance(uuc,yukari)=distance(uuc,yukari)+hmin;
            end
        end
    end
    
    
    for uuc=1:slength
        if cols(uuc,1)==1
            for yukari=1:slength
                distance(yukari,uuc)=distance(yukari,uuc)+hmin;
            end
        end
    end
   
   
    
    %step 7
    distance=distance-min(min(distance));
    
    
    
    %step 8
    [rows cols count]=cover(distance,slength);
    
    
end

assign2=zeros(slength,2);
%step 9
count=1;
row=zeros(slength,1);
col=zeros(slength,1);

for uuc=1:slength
    if length(find(distance(uuc,:)==0))==1
        for yukari=1:slength
            if distance(uuc,yukari)==0
                assign2(count,1)=mod(uuc,llength);
                assign2(count,2)=yukari;
                row(uuc)=1;
                col(yukari)=1;
                count=count+1;
            end
        end
    end
end

for uuc=1:slength
    if length(find(distance(:,uuc)==0))==1
        for yukari=1:slength
            if distance(yukari,uuc)==0 && row(yukari,1)~=1 && col(uuc,1)~=1
                assign2(count,1)=mod(yukari,llength);
                assign2(count,2)=uuc;
                row(yukari,1)=1;
                col(uuc,1)=1;
                count=count+1;
            end
        end
    end
end


for uuc=1:slength
    for yukari=1:slength
        if distance(uuc,yukari)==0 && row(uuc,1)~=1 && col(yukari,1)~=1
            assign2(count,1)=mod(uuc,llength);
            assign2(count,2)=yukari;
            row(uuc,1)=1;
            col(yukari,1)=1;
            count=count+1;
            break;
        end
    end
end
Corr=assign2;
end

