function img = BuildParallelismTestImage(ver,options)
if(nargin < 2)
  options = [];
end

d.ndots = 256;
d.dotsize = 1;
d.nParReps = 4;
d.fPurity = 1;
d.size = 128;
d.padsize = 0;
d.bRifle = 1;
options=ResolveMissingOptions(options,d);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(ver == 1)
  nrepsets = floor(options.fPurity * options.ndots/options.nParReps);
  nadditional = options.ndots - nrepsets*options.nParReps;
  sz = (options.size - 2*options.padsize);
  if(options.bRifle), sz = floor(sz/2); end
  fs = floor(sz / options.nParReps);
  p1 = floor(rand(nrepsets,1) * sz + 1);
  p2 = floor(rand(nrepsets,1) * fs + 1);
  parimg = zeros(sz);
  for i = 1:options.nParReps
    parimg(p1 + sz * (p2-1 + (i-1) * fs)) = 1;
  end
  ds = options.dotsize - 1;
  cds = ceil(ds/2);
  fds = floor(ds/2);
  parimg = maxfilter(parimg, [cds cds fds fds]);
  nparimg = zeros(sz);
  p1 = floor(rand(nadditional,1) * sz + 1);
  p2 = floor(rand(nadditional,1) * sz + 1);
  nparimg(p1 + sz * (p2-1)) = 1;
  nparimg = maxfilter(nparimg, [cds cds fds fds]);
  img = (parimg + nparimg) > 0;
  if(options.bRifle)
    img = rifle(img);
    if(mod(options.size,2))
       img = padimage(img,[0 0 1 1],0);
    end
  end  
  img = padimage(img,options.padsize,0);
end  
  
  




function i2 = rifle(i1)
i2 = zeros(2*size(i1));
i2(2:2:end,2:2:end) = i1;

function i2 = Duplicate_LR(i1);
sz = size(i1,2);
i2 = i1;
i2(:,1:(floor(sz/2))) = i1(:,(sz - floor(sz/2)+1):sz);

function i2 = Duplicate_UD(i1);
sz = size(i1,1);
i2 = i1;
i2(1:(floor(sz/2)),:) = i1((sz - floor(sz/2)+1):sz,:);
