
disp(['Displaying the templates']);
selecta = zeros(1, nimage); 
symselect = cell(1, nimage); 
[tssmeansort, indmean] = sort(tssmean, 'descend'); 
counta = 0; 
insid = zeros(1, nimage)+1.; 
for (i=1:nimage)
  j = indmean(i);
  if (insid(j)>.5)
      counta = counta + 1; 
      symselect{counta} = symAll{j}+0.; 
      selecta(counta) = j; 
      for (q = 1:K)
        for (g = 1:nimage)
            if (abs(g-inde(j, q))<.1)
                %insid(g) = 0.; 
            end
        end 
    end
  end
end

bx =0; by = 0; cc = 3;
col = 12; row = floor(counta/col)+1;
Iout = zeros(row*sx+(row-1)*(2*bx+cc), col*sy+(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)*sx+1+(r-1)*(2*bx+cc): r*sx+(r-1)*(2*bx+cc), (c-1)*sy+1+(c-1)*(2*by+cc): (c-1)*sy+sy+(c-1)*(2*by+cc)) = towrite; 
        end
    end
end
for (r = 1 : row-1)
  Iout(r*sx+(r-1)*(2*bx+cc)+bx+1:r*sx+(r-1)*(2*bx+cc)+bx+cc, :) = 0; 
end
for (c = 1 : col-1)
  Iout(:, c*(sy)+(c-1)*(2*by+cc)+by+1:c*(sy)+(c-1)*(2*by+cc)+by+cc) = 0; 
end
outepsgif(Iout, ['ex9_1_represent_all']); 


