function [H, pts_out] = Normalize( pts_in )
%Code written by Jim Patrick for project 2 in CEG725 2/16/2009
%normalized points by centering them about the centroid and also setting
%the average length to sqrt(2)
[m n] = size(pts_in);
if m < 3, pts_in = [pts_in; ones(1,n)]; end
x_bar = mean(pts_in(1,:));
y_bar = mean(pts_in(2,:));

d = sum(sqrt((pts_in(1,:)-x_bar).^2+(pts_in(2,:)-y_bar).^2)) / (n*sqrt(2));
pts_out = [(pts_in(1,:)-x_bar)./d; (pts_in(2,:)-y_bar)./d; ones(1,n)];
H = (pts_in'\pts_out')';
b=1;
