%
% runTests.m
%

%----------------------flieger2----------------------------------

% images
fprintf('====================================================\n');
fprintf('=============== Flieger2 ===========================\n');
fprintf('====================================================\n');

temp = 255*double(ppmread2('../images/flieger2_center.ppm'));
temp = rgb2ycbcr(temp);
Itarget = temp(:,:,1);
temp = 255*double(ppmread2('../images/flieger2_left.ppm'));
temp = rgb2ycbcr(temp);
Irefs{1} = temp(:,:,1);
temp = 255*double(ppmread2('../images/flieger2_right.ppm'));
temp = rgb2ycbcr(temp);
Irefs{2} = temp(:,:,1);
temp = 255*double(ppmread2('../images/flieger2_top.ppm'));
temp = rgb2ycbcr(temp);
Irefs{3} = temp(:,:,1);
temp = 255*double(ppmread2('../images/flieger2_bottom.ppm'));
temp = rgb2ycbcr(temp);
Irefs{4} = temp(:,:,1);

allLambdas = [0, 5, 25, 125, 625, 3125];

% fix disparities, vary blocksize
indices = [16:33];
pdf = [1 1 1 1 2 7 6 4 10 10 4 6 7 2 1 1 1 1];
for blocksize = [4 8 32]

  fprintf('****** BLOCKSIZE = %i *******\n', blocksize); 
  
  scheme = 'std';
  runAll;
  R_std = R;
  D_std = D;
  Ipredict_std = Ipredict;
  
  scheme = 'h1';
  runAll;
  R_h1 = R;
  D_h1 = D;
  Ipredict_h1 = Ipredict;
  
  scheme = 'h2';
  runAll;
  R_h2 = R;
  D_h2 = D;
  Ipredict_h2 = Ipredict;
  
  outfile = sprintf('flieger2_block%i_disp1', blocksize);
  fprintf('Saving to matfile: %s\n', outfile);
  save(outfile);
end

% fix blocksize, vary disparity values
blocksize = 16;

%--------
indices = [16:2:32];
pdf = [2 2 9 10 20 10 9 2 2];
scheme = 'std';
runAll;
R_std = R;
D_std = D;
Ipredict_std = Ipredict;

scheme = 'h1';
runAll;
R_h1 = R;
D_h1 = D;
Ipredict_h1 = Ipredict;

scheme = 'h2';
runAll;
R_h2 = R;
D_h2 = D;
Ipredict_h2 = Ipredict;

outfile = sprintf('flieger2_block16_disp2');
fprintf('Saving to matfile: %s\n', outfile);
save(outfile);

%-------
indices = [17:3:32];
pdf = [3 10 20 20 10 3];
scheme = 'std';
runAll;
R_std = R;
D_std = D;
Ipredict_std = Ipredict;

scheme = 'h1';
runAll;
R_h1 = R;
D_h1 = D;
Ipredict_h1 = Ipredict;

scheme = 'h2';
runAll;
R_h2 = R;
D_h2 = D;
Ipredict_h2 = Ipredict;

outfile = sprintf('flieger2_block16_disp3');
fprintf('Saving to matfile: %s\n', outfile);
save(outfile);



%----------------------flieger1----------------------------------

fprintf('====================================================\n');
fprintf('=============== Flieger1 ===========================\n');
fprintf('====================================================\n');

% images
temp = 255*double(ppmread2('../images/flieger1_center.ppm'));
temp = rgb2ycbcr(temp);
Itarget = temp(:,:,1);
temp = 255*double(ppmread2('../images/flieger1_left.ppm'));
temp = rgb2ycbcr(temp);
Irefs{1} = temp(:,:,1);
temp = 255*double(ppmread2('../images/flieger1_right.ppm'));
temp = rgb2ycbcr(temp);
Irefs{2} = temp(:,:,1);
temp = 255*double(ppmread2('../images/flieger1_top.ppm'));
temp = rgb2ycbcr(temp);
Irefs{3} = temp(:,:,1);
temp = 255*double(ppmread2('../images/flieger1_bottom.ppm'));
temp = rgb2ycbcr(temp);
Irefs{4} = temp(:,:,1);

allLambdas = [0, 5, 25, 125, 625, 3125];

% fix disparities, vary blocksize
indices = [16:33];
pdf = [1 1 1 1 2 7 6 4 10 10 4 6 7 2 1 1 1 1];
for blocksize = [4 8 16 32]

  fprintf('****** BLOCKSIZE = %i *******\n', blocksize); 
  
  scheme = 'std';
  runAll;
  R_std = R;
  D_std = D;
  Ipredict_std = Ipredict;
  
  scheme = 'h1';
  runAll;
  R_h1 = R;
  D_h1 = D;
  Ipredict_h1 = Ipredict;
  
  scheme = 'h2';
  runAll;
  R_h2 = R;
  D_h2 = D;
  Ipredict_h2 = Ipredict;
  
  outfile = sprintf('flieger1_block%i_disp1', blocksize);
  fprintf('Saving to matfile: %s\n', outfile);
  save(outfile);
end

% fix blocksize, vary disparity values
blocksize = 16;

%--------
indices = [16:2:32];
pdf = [2 2 9 10 20 10 9 2 2];
scheme = 'std';
runAll;
R_std = R;
D_std = D;
Ipredict_std = Ipredict;

scheme = 'h1';
runAll;
R_h1 = R;
D_h1 = D;
Ipredict_h1 = Ipredict;

scheme = 'h2';
runAll;
R_h2 = R;
D_h2 = D;
Ipredict_h2 = Ipredict;

outfile = sprintf('flieger1_block16_disp2');
fprintf('Saving to matfile: %s\n', outfile);
save(outfile);

%-------
indices = [17:3:32];
pdf = [3 10 20 20 10 3];
scheme = 'std';
runAll;
R_std = R;
D_std = D;
Ipredict_std = Ipredict;

scheme = 'h1';
runAll;
R_h1 = R;
D_h1 = D;
Ipredict_h1 = Ipredict;

scheme = 'h2';
runAll;
R_h2 = R;
D_h2 = D;
Ipredict_h2 = Ipredict;

outfile = sprintf('flieger1_block16_disp3');
fprintf('Saving to matfile: %s\n', outfile);
save(outfile);

