% Image Registration
% Read in images
orthophoto = imread('westconcordorthophoto.png');
figure, imshow(orthophoto)
unregistered = imread('westconcordaerial.png');
figure, imshow(unregistered)

% Choose control points and save the Control Point Pairs to the MATLAB Workspace
cpselect(unregistered(:,:,1),orthophoto)

% Specify the Type of Transformation and Infer its Parameters
mytform = cp2tform(input_points,base_points,'projective');

% Transform the Unregistered Image
registered = imtransform(unregistered,mytform);

% fit the registered image into the orthophoto image

% reg_gray = rgb2gray(registered);
% reg_gray_size = imresize(reg_gray, size(orthophoto));
% 
% mask_reg = reg_gray_size;
% mask_reg(reg_gray_size > 30) = 255;
% test_orig = imsubtract(orthophoto,mask_reg);
% imshow(test_orig)
% 
% mask_reg = (mask_reg ==  255);
% test_reg = immultiply(reg_gray_size,mask_reg);
% figure
% imshow(imadd(test_orig,test_reg))