function img = BuildContinuityTestImage(options)
if(nargin < 1)
  options = [];
end

d.fPurity = .5;
d.size = 81;
d.padsize = 0;
d.bRifle = 1;

options=ResolveMissingOptions(options,d);
sz = (options.size - 2*options.padsize);
if(options.bRifle), sz = floor(sz/2); end
hs = floor(sz / 2);
% pick a point on the continuous line
centerDist = hs * 2;
while(centerDist > (hs/2)) % the line must pass within the largest circle within the square image.
   lp_yx = floor(rand(1,2) * sz);
   centerDist = norm(hs - lp_yx);
end
% pick orientation
th = rand * pi;
slope = tan(th);
% fill line
contimg = zeros(sz);
if(abs(slope) <= 1)
  for i_x = 1:sz
    i_y = floor(lp_yx(1) + (slope * (-i_x+lp_yx(2))));
    if ((i_y >= 1) && (i_y <= sz))
      contimg(i_y,i_x) = 1;
    end
  end  
else
  for i_y = 1:sz
    i_x = floor(lp_yx(2) + ((1/slope) * (-i_y+lp_yx(1))));
    if ((i_x >= 1) && (i_x <= sz))
      contimg(i_y,i_x) = 1;
    end
  end  
end
img = contimg;
img = img(:);
% add noize
nPip = sum(img);
n2move = floor(nPip * (1-options.fPurity));
f = find(img);
p = randperm(length(f));
f = f(p);
for i = 1:n2move
  f(i) = ceil(rand * sz * sz);
end
img = zeros(sz);
img(f) = 1;
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);
  
  

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

