
disp(['Displaying the templates']);
redu = 0; 
selecta = zeros(1, numImage); 
symselect = cell(1, numImage); 
[meanSUM2scoresort, indmean] = sort(meanSUM2score, 'descend'); 
counta = 0; 
insid = zeros(1, numImage)+1.; 
for (i=1:numImage)
  j = indmean(i);
  showit = 1.; 
  for (q = 1:numNeighbor-redu)
      if (insid(neighbor(j, q))<.5)
          showit = 0.; 
      end
  end
  if (showit>.5)
      counta = counta + 1; 
      symselect{counta} = allTemplate{j}+0.; 
      selecta(counta) = j; 
      for (q = 1:numNeighbor-redu)
          insid(neighbor(j, q)) = 0.;
       end
  end
end

bx =0; by = 0; cc = 3;
col = 8; row = floor(counta/col - .001) + 1;
Iout = zeros(row*sizex+(row-1)*(2*bx+cc), col*sizey+(col-1)*(2*by+cc))+255; 
i = 0;  
for (r = 1 : row)
    for (c = 1 : col)
        i = i+1;  
        if (i<=counta)
            towrite = -symselect{i}; 
            towrite = (255 * (towrite-min(towrite(:)))/(max(towrite(:))-min(towrite(:))));
            Iout((r-1)*sizex+1+(r-1)*(2*bx+cc): r*sizex+(r-1)*(2*bx+cc), (c-1)*sizey+1+(c-1)*(2*by+cc): (c-1)*sizey+sizey+(c-1)*(2*by+cc)) = towrite; 
        end
    end
end
for (r = 1 : row-1)
  Iout(r*sizex+(r-1)*(2*bx+cc)+bx+1:r*sizex+(r-1)*(2*bx+cc)+bx+cc, :) = 0; 
end
for (c = 1 : col-1)
  Iout(:, c*(sizey)+(c-1)*(2*by+cc)+by+1:c*(sizey)+(c-1)*(2*by+cc)+by+cc) = 0; 
end
outepsgif(Iout, ['ex9_1_represent_trim']); 


