function [img, plist, npoints] = generate_im_list(im, nsite, template)

img = im;

plist = zeros([nsite 2]);
npoints = 0;
for i=1:nsite,
  row = floor(rand*(size(img,1)-size(template,1)))+1;
  col = floor(rand*(size(img,2)-size(template,2)))+1;
  
  patch = img(row:(row+ size(template,1)-1), col:(col+size(template,2)-1));
  if sum(sum(patch < 120)) < 0.5,
    img(row:(row+ size(template,1)-1), col:(col+size(template,2)-1)) = template;
    npoints=npoints+1;
    plist(npoints,1)=row;
    plist(npoints,2)=col;
  end
end
image(img);
msg = sprintf('Size (%d,%d) with %d templates.', size(img,1), size(img,2), npoints);
title(msg);
axis('off');
axis('image');
return;

