%% We can also have matlab do attempt to find a transform for us
clear
close all

img1 = im2double(imread('westconcordorthophoto.png'));
img2 = rgb2gray(im2double(imread('westconcordaerial.png')));

% imregconfig starts variables that we will use to align the images.  If
% the images are taken on the same system, choose monomodal, if they are
% different devices, multimodal.
[optimizer, metric] = imregconfig('monomodal');

% Use the imregister command to align the two images.  The arguments are
% the moving image, the fixed image, the type of transform, and the
% optimizer and metric generated from above.
newImg = imregister(img1,img2,'similarity',optimizer,metric);

figure
imshowpair(newImg,img2)


%% Time cost of different registration transforms
% A convienent function is the tic/toc.  It tells you how much has time has
% gone by between the tic and toc.

tic
pause(1)
toc

% We can use this to time how long it takes matlab to try the different
% registration transforms.
rigidTic = tic;
newImg1 = imregister(img1,img2,'rigid',optimizer,metric);
disp(['Time to complete rigid registration: ']);
toc(rigidTic)
figure
imshowpair(newImg1,img2)

similarityTic = tic;
newImg2 = imregister(img1,img2,'similarity',optimizer,metric);
disp(['Time to complete similarity registration: ']);
toc(similarityTic)
figure
imshowpair(newImg2,img2)

affineTic = tic;
newImg2 = imregister(img1,img2,'affine',optimizer,metric);
disp(['Time to complete similarity registration: ']);
toc(affineTic)
figure
imshowpair(newImg2,img2)


