function grouping(sampleLabels)
global im imgVector vectorMap height width wnd c xx vheight vwidth

group=max(sampleLabels);
hn=hist(sampleLabels,[min(sampleLabels):max(sampleLabels)]);
l=round(wnd/2);
r=round(wnd/2-0.5);
num = min(1000,vheight*vwidth);

for i=1:vheight
   for j=1:vwidth     
        t=imgVector(:,(i-1)*vwidth+j);
       %initialize the distance vector
       dist=zeros(1,num);
       %calculate the distances to the 1000 sampled vectors
       for gi=1:num
           dist(gi)=sum((t(:,1)-xx(:,gi)).^2);
       end
       %choose the nearest vector
       [mindist idx]=min(dist);
       %label current pixel
       vectorMap(i,j)=sampleLabels(idx);
   end
end