I1 = imread('1.jpg');
I2 = imread('2.jpg');
I3 = imread('3.jpg');
I4 = imread('4.jpg');

I1 = imresize(I1,0.25,'nearest');
I2 = imresize(I2,0.25,'nearest');
I3 = imresize(I3,0.25,'nearest');
I4 = imresize(I4,0.25,'nearest');


H = [1 0 400; 0 1 100; 0 0 1];
tform = maketform('projective',H');
Base = imtransform(I2,tform,'nearest','xyscale',1,...
                'xdata', [1 2000], 'ydata', [1 1000],...
                'fillvalues', 0);
            
figure;            
imshow(Base);
P1_Base = ginput();
hold on;
scatter(P1_Base(:,1),P1_Base(:,2));
hold off;
figure;
imshow(I1);
P1 = ginput();
hold on;
scatter(P1(:,1),P1(:,2));
hold off;

H = Compute_H(P1,P1_Base); 
tform = maketform('projective',H');
Base_tmp = imtransform(I1,tform,'nearest','xyscale',1,...
                'xdata', [1 2000], 'ydata', [1 1000],...
                'fillvalues', 0);
Base = gra_proc(Base_tmp,Base);


figure;            
imshow(Base);
P3_Base = ginput();
hold on;
scatter(P3_Base(:,1),P3_Base(:,2));
hold off;
figure;
imshow(I3);
P3 = ginput();
hold on;
scatter(P3(:,1),P3(:,2));
hold off;

H = Compute_H(P3,P3_Base); 
tform = maketform('projective',H');
Base_tmp = imtransform(I3,tform,'nearest','xyscale',1,...
                'xdata', [1 2000], 'ydata', [1 1000],...
                'fillvalues', 0);
Base = gra_proc(Base_tmp,Base);

figure;            
imshow(Base);
P4_Base = ginput();
hold on;
scatter(P4_Base(:,1),P4_Base(:,2));
hold off;
figure;
imshow(I4);
P4 = ginput();
hold on;
scatter(P4(:,1),P4(:,2));
hold off;

H = Compute_H(P4,P4_Base); 
tform = maketform('projective',H');
Base_tmp = imtransform(I4,tform,'nearest','xyscale',1,...
                'xdata', [1 2000], 'ydata', [1 1000],...
                'fillvalues', 0);
Base = gra_proc(Base_tmp,Base);

figure;
imshow(Base);