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

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(ver == 1)
  img = rand(128) .^ 5;
  img(1:64,1:64) = MakeSymm_LR(img(1:64,1:64));
  img(65:96,1:32) = MakeSymm_LR(img(65:96,1:32));
  img(65:96,33:64) = MakeSymm_LR(img(65:96,33:64));
  img(97:128,1:32) = MakeSymm_LR(img(97:128,1:32));
  img(97:128,33:64) = MakeSymm_LR(img(97:128,33:64));
  
  img(1:64,65:128) = MakeSymm_UD(img(1:64,65:128));
  img(65:96,64+(1:32)) = MakeSymm_UD(img(65:96,64+(1:32)));
  img(65:96,64+(33:64)) = MakeSymm_UD(img(65:96,64+(33:64)));
  img(97:128,64+(1:32)) = MakeSymm_UD(img(97:128,64+(1:32)));
  img(97:128,64+(33:64)) = MakeSymm_UD(img(97:128,64+(33:64)));
end
if(ver == 2)
  nsymmpair = floor(options.fSymmness * options.ndots/2);
  nnotsymm = options.ndots - 2*nsymmpair;
  sz = (options.size - 2*options.padsize);
  if(options.bRifle), sz = floor(sz/2); end
  hs = floor(sz / 2);
  p1 = floor(rand(nsymmpair,1) * sz + 1);
  p2 = hs + floor(rand(nsymmpair,1) * hs + 1);
  symmimg = zeros(sz);
  symmimg(p1 + sz * (p2-1)) = 1;
  ds = options.dotsize - 1;
  cds = ceil(ds/2);
  fds = floor(ds/2);
  symmimg = maxfilter(symmimg, [cds cds fds fds]);
  symmimg(1:sz,1:sz) = MakeSymm_LR(symmimg(1:sz,1:sz));
  nsymmimg = zeros(sz);
  p1 = floor(rand(nnotsymm,1) * sz + 1);
  p2 = floor(rand(nnotsymm,1) * sz + 1);
  nsymmimg(p1 + sz * (p2-1)) = 1;
  nsymmimg = maxfilter(nsymmimg, [cds cds fds fds]);
  img = (symmimg + nsymmimg) > 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 = MakeSymm_LR(i1);
sz = size(i1,2);
i2 = i1;
i2(:,1:(floor(sz/2))) = i1(:,sz:-1:(sz - floor(sz/2)+1));

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