%This software implements the point matching algorithm described in the paper:
%"Rotation Invariant Nonrigid Point Set Matching in Cluttered Scenes", IEEE transaction on Image Processing, 2012

%Author: Wei Lian (Changzhi University, Changzhi, 046011, Shanxi Province, P.R. China, Email: lianwei3 at gmail.com)

%If you use this software for research purposes, you should cite the aforementioned paper in any resulting publications.


function neig=nearest_neighbour(dist,num)
%%num: number of nearest neighbours
%%neig: matrix contains indices of nearest neighbours for each point, num x N

N=size(dist,1);
neig=zeros(num,N);
for ii=1:num
    mindist=min(dist);
    for jj=1:N
        ind=find(dist(:,jj)==mindist(jj));
        neig(ii,jj)=ind(1);
        dist(ind(1),jj)=inf;
    end
end
