% Complete HSM algorithm: find the roto-translations that
% overlap two sets of points.
%
% With respect to test1.m and test2.m, we now encapsulate
% much of the functionalities in external functions
function result =test3

% We create the first set of points

	holmes = imread('holmes.pgm');
	edges=edge(holmes);
	[pointsX,pointsY]=find(edges>0);
	points1=[pointsX-128 pointsY-128]'/256.0;

	size(points1)
% We sample a random roto-translation
	
	% translation
	T = rand(2,1)
	
	% rotation, between -pi and pi
	theta = (rand)*2*pi
	

% We do a roto-translation of the first set and then
% add some noise

	points2 = points1;
	
	% translation
	points2 = points2 + repmat(T,1,size(points2,2));
	% rotation
	points2 = rotationMatrix(theta) * points2;
	
	% add noise
	noise = 0.04;
	points2 = points2 + noise * randn(2, size(points2,2));

% We create this object "params" to hold the parameters
	params.thetaCells = 360;
	params.rhoCells = 200;
	params.rhoScale = 3;
	params.points1 = points1;
	params.points2 = points2;
	params.maxPhiHypotheses = 4;
	params.maxTHypotheses = 2;
	params.phiFilterSigma = 15;
	params.rhoFilterSigma = 4;
	params.maxRhoCorrelations = 8;
	params.maxTBound = 1.1;
	
	result = doHSM(params);
	
	[f1,f2] = displayHSMResult(result);
	
	figure(f1);
	set(gcf, 'PaperPositionMode', 'auto');
	set(gcf, 'position', [0 0 400 800])
	print -depsc2 -tiff testImageHolmes-phi.eps
	print -dpng testImageHolmes-phi.png
	figure(f2);
	set(gcf, 'PaperPositionMode', 'auto');
	set(gcf, 'position', [0 0 400 400])
	print -depsc2 -tiff testImageHolmes-t.eps
	print -dpng  testImageHolmes-t.png
	
