function [imo,T,pts] = CS4640_con_reg(ref,im)
%

SIDE = 10;

[M,N] = size(ref);
imo = zeros(M,N);

cp = [697, 260;...   % Control points from im1 of traffic sequence
      283, 634;...
       71,1092;...
      930,1298;...
      707,1640;...
      129,1904];

num_cp = length(cp(:,1));
pts = [cp,zeros(num_cp,2)];

for p = 1:num_cp
    W1 = ref(cp(p,1)-SIDE:cp(p,1)+SIDE,cp(p,2)-SIDE:cp(p,2)+SIDE);
    pp = CS4640_correl(double(W1),double(im));
    [rows,cols] = find(pp==max(max(pp)));
    if length(rows)>1
        num_rows = length(rows);
        dists = zeros(num_rows,1);
        for r = 1:num_rows
            dists(r) = norm(cp(p,1:2)-[rows(r),cols(r)]);
        end
        [val,index] = min(dists);
        pts(p,3) = rows(index);
        pts(p,4) = cols(index);
    else
        pts(p,3) = rows(1);
        pts(p,4) = cols(1);
    end
end

[imo,T] = CS4640_register(ref,im,pts);
tch = 0;
