%       T = NORMU(u) finds normalization matrix T so that
%       mean(T*u)=0 and mean(||T*u||)=sqrt(2).
%       (see Hartley: In Defence of 8-point Algorithm, ICCV`95).
%       Parameters:
%         u ... Size (2,N) or (3,N). Points to normalize.
%         T ... Size (3,3). Normalization matrix.

function T = normu(u);
 
m = mean(u(1:2,:),2);
u = u(1:2,:) - m*ones(1,size(u,2));
distu = sqrt(sum(u.*u));
r = mean(distu)/sqrt(2);
T  = diag([1/r 1/r 1]);
T(1:2,3) = -m/r;

