% This code demonstrates how a simple addition of matrices can be used to
%  blend two (or more) images.

load mygatlin_2            % loading th eimage file with photographs of
                           %  (left to right): J. Wilkinson, W. Givens, G. Forsythe.

figure(1);                           
image(X);                  % displaying the matrix of the photograph as a picture
colormap(map);             % this just has to be here to display correct colors
title('Wilkinson, Givens, Forsythe','fontsize',14)

W=X(26:125, 1:75);         % extract a submatrix with a close-up of Wilkinson;
                           %  this matrix has 125-26+1=100 rows and 75-1+1=75 columns
                           
figure(2); 
image(W);                  % displaying the photograph of Wilkinson alone
colormap(map);          
title('Wilkinson','fontsize',14)

% Repeat the above steps for Givens:
G=X(21:120, 96:170);       % extract a submatrix with a close-up of Givens;
                           %  note that this matrix has the same dimension as W
                           
                           
figure(3); 
image(G);                  % displaying the photograph of Givens alone
colormap(map);          
title('Givens','fontsize',14)

tmin=-1;                   % min, max, and increment of  t
tmax=2;
dt=0.02;             
t=tmin;                    % starting value of  t

figure(4); 
title('Linear Combination = (1-t)W + tG','fontsize',13)
disp('hit any key to continue')
pause;


while  t <= tmax+eps          
    WtG = (1-t)*W + t*G;   % creating the blended image of Wilkinson and Givens
    figure(4); 
    image(WtG);            % displaying the blended image of Wilkinson and Givens
    colormap(map);    
    if abs(t) > 100*eps
        taux=t+0.0001*sign(t);
    else
        taux=0;
    end
    title(['t = ' num2str(taux)],'fontsize',19) 
    pause(0.4)
    t=t+dt;                % increment the value of  t
end




