% Demo_align: (sctript)
% Demo with different alignment experiments:
%  'alignment'
%  'blck_alignment' - for large size images (avoid memory problems)

clear all

% change here the algnment experiment:
experiment = 'blck_alignment'; 
% experiment = 'alignment'; 


switch lower(experiment)
    case {'blck_alignment'}
        mix1_str='carta1_al.bmp';
        mix2_str='carta2_al.bmp';
        mix1 = imread(mix1_str);
        mix2 = imread(mix2_str);
        mix1 = mix1(1:end,1:end);
        mix2 = mix2(1:end,1:end);
        mix1 = mix1(200:700,200:700);
        mix2 = mix2(200:700,200:700);
        
        delta_al1=6;  % max aligment size (in pixels)
        rez=4;        % aligment resolution (1/rez pixels)
        nblocos_i = 2; % number of blocks in the vertical-axis   (yy)
        nblocos_j = 2; % number of blocks in the horizontal-axis (xx)

        block_alignment_script
        %         [mix1a mix2a]=block_alignment(mix1, mix2, delta_al1 , rez, nblocos_i, nblocos_j );
        
        figure, imagesc( mix1-mix2), colormap gray , title('Img1-Img2 (Before aligment)')
        figure, imagesc( mix1_a-mix2_a), colormap gray , title('Img1-Img2 (Before aligment)')
        
    case {'alignment'}
        % Load data:
        mix1_str='carta1_align.bmp';
        mix2_str='carta2_align.bmp';
        mix1 = double(imread(mix1_str));
        mix2 = double(imread(mix2_str));
        mix1k = mix1(200:700,200:700);
        mix2k = mix2(200:700,200:700);
        clear mix1 mix2, pack
        
        delta_al1=6;  % max aligment size (in pixels)
        rez=4;        % aligment resolution (1/rez pixels)

         alignment_script
         % [mix1a mix2a]=alignment(mix1k, mix2k, delta_al1 , rez);
        
        figure, imagesc( mix1k-mix2k), colormap gray , title('Img1-Img2 (Before aligment)')
        figure, imagesc( mix1a-mix2a), colormap gray , title('Img1-Img2 (Before aligment)')
end
