% ortofoto demo - data upravena z klad55.jpg 
% http://geoportal.cuzk.cz/UKAZKOVA_DATA/ORTOFOTO_JPG.zip

url = 'http://geo.fsv.cvut.cz/user/gin/git1/matlab/img/';
A = imread(strcat(url, 'klad55-ortofoto.jpg')); % ortofoto snimek (vyrez)      
B = imread(strcat(url, 'klad55-perspektiva.jpg'));

A_ib = [115 123; 445 177; 467 302; 332 362; 
        279 446;  95 234; 389 465; 170 533];
B_ib = [ 42  93; 409  70; 467 174; 345 260; 
        312 353;  48 200; 436 337; 214 467];
    
%{
info = imfinfo('ORTOFOTO/B.jpg');
P = cp2tform(B_ib, A_ib, 'projective');
Q = imtransform(B, P, 'XData',[1 info.Width], 'YData',[1 info.Height]);
%}
% obraz B je trucolor, tj. pole o trech dimenzich, viz XData a YData
P = cp2tform(B_ib, A_ib, 'projective');
Q = imtransform(B, P, 'XData',[1 size(B,2)+80], 'YData',[1 size(B,1)+163]);

figure(1), imshow(A);
figure(2), imshow(B);
figure(3), imshowpair(A, Q, 'blend'); 
figure(4), imshow(Q);
figure(5), imshowpair(A, Q, 'falsecolor');

imwrite(Q,'klad55-vystup.png','png');
R = imfuse(A, Q, 'blend'); 
imwrite(R,'klad55-blend.png','png');
S = imfuse(A, Q, 'falsecolor'); 
imwrite(S,'klad55-falsecolor.png','png');
