%  This function generates a snowy image with randomly placed
%  prints going across it.  The prints obey the stride, straddle
%  and intergroup values of the various images.
function [S] = Generate(bigimsize)
  imsize = 32;
  Sold = zeros(bigimsize);
  imnum = 1;
  %  The information about the various animals
  while imnum<4
    switch imnum
     case{1}
      A = Loadin('myboot.tif');
      stride = 60;
      straddle = 20;
      intergroup = 30;
      prints = ceil(bigimsize/stride);
     case{2}
      A = Loadin('mydeer.tif');
      stride = 120;
      straddle = 25;
      intergroup = 20;
      prints = ceil(bigimsize/stride);
     case{3}
      A = Loadin('mybobcat.tif');
      stride = 90;
      straddle = 30;
      intergroup = 30;
      prints = ceil(bigimsize/stride);
    end
    A = A - .5.*ones(imsize);
    SA = zeros(stride*prints+imsize+intergroup, straddle+imsize);
    %  Place the prints in a column
    for index = 0:1:prints
      SA(1+index*stride:imsize+index*stride,1:imsize) = ...
	SA(1+index*stride:imsize+index*stride,1:imsize)+A;
      SA(1+intergroup+index*stride:imsize+intergroup+index*stride,...
	1+straddle:imsize+straddle)=SA(1+intergroup+index*stride:...
	imsize+intergroup+index*stride,1+straddle:imsize+straddle)+fliplr(A);
    end
    %  Rotate the prints through a random angle
    a = 30*round(6*(rand(1)-.5));
    SA = imrotate(SA, a);
    SA = [zeros(size(SA,1),round(bigimsize/4*rand(1))),SA];
    SA = [zeros(round(bigimsize/4*rand(1)), size(SA,2));SA];
    %  Crop the image
    while(size(SA, 1)>bigimsize)
      SA = SA(2:size(SA,1)-1, :);
    end
    while(size(SA, 2)>bigimsize)
      SA = SA(:, 2:size(SA,2)-1);
    end
    %  Pad the images back to full size
    if size(SA, 1)<bigimsize
      if rand(1)>.5
	SA = [SA; zeros(bigimsize-size(SA,1),size(SA,2))];
      else
	SA =  [zeros(bigimsize-size(SA,1),size(SA,2)); SA];
      end
    end
    if size(SA,2)<bigimsize
      if rand(1)>.5
	SA = [SA, zeros(size(SA,1),bigimsize-size(SA,2))];
      else
	SA = [zeros(size(SA,1),bigimsize-size(SA,2)),SA];
      end
    end
    %  Check to make sure the tracks don't overlap
    S = Sold+SA;
    if min(min(S))<=-2
      S = Sold;
      imnum= imnum-1;
    else
      Sold = S;
    end
    imnum = imnum+1;
  end
  %  Renormalize our matrix
  S = Sold+.5.*ones(bigimsize);




