function faces_average_test ( )

%*****************************************************************************80
%
%% FACES_AVERAGE_TEST tests FACES_AVERAGE.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    23 December 2018
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../faces_average' );

  clear all

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'FACES_AVERAGE_TEST:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Compute average of several images of a face.\n' );
  fprintf ( 1, '\n' );
%
%  Emma Stone.
%
  A(:,:,1) = imread ( '../../datasets/faces_emma_stone/emma01_gray.jpg' );
  A(:,:,2) = imread ( '../../datasets/faces_emma_stone/emma02_gray.jpg' );
  A(:,:,3) = imread ( '../../datasets/faces_emma_stone/emma03_gray.jpg' );
  A(:,:,4) = imread ( '../../datasets/faces_emma_stone/emma04_gray.jpg' );
  A(:,:,5) = imread ( '../../datasets/faces_emma_stone/emma05_gray.jpg' );
  A(:,:,6) = imread ( '../../datasets/faces_emma_stone/emma06_gray.jpg' );
  A(:,:,7) = imread ( '../../datasets/faces_emma_stone/emma07_gray.jpg' );
  A(:,:,8) = imread ( '../../datasets/faces_emma_stone/emma08_gray.jpg' );
  A(:,:,9) = imread ( '../../datasets/faces_emma_stone/emma09_gray.jpg' );
  A(:,:,10) = imread ( '../../datasets/faces_emma_stone/emma10_gray.jpg' );

  A_average = faces_average ( A );

  figure ( 1 )
  clf
  imshow ( A_average );
  title ( 'Average Emma Stone' );
  filename = 'emma_average.jpg';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Taylor Swift
%
  B(:,:,1) = imread ( '../../datasets/faces_taylor_swift/taylor01_gray.jpg' );
  B(:,:,2) = imread ( '../../datasets/faces_taylor_swift/taylor02_gray.jpg' );
  B(:,:,3) = imread ( '../../datasets/faces_taylor_swift/taylor03_gray.jpg' );
  B(:,:,4) = imread ( '../../datasets/faces_taylor_swift/taylor04_gray.jpg' );
  B(:,:,5) = imread ( '../../datasets/faces_taylor_swift/taylor05_gray.jpg' );
  B(:,:,6) = imread ( '../../datasets/faces_taylor_swift/taylor06_gray.jpg' );
  B(:,:,7) = imread ( '../../datasets/faces_taylor_swift/taylor07_gray.jpg' );
  B(:,:,8) = imread ( '../../datasets/faces_taylor_swift/taylor08_gray.jpg' );
  B(:,:,9) = imread ( '../../datasets/faces_taylor_swift/taylor09_gray.jpg' );
  B(:,:,10) = imread ( '../../datasets/faces_taylor_swift/taylor10_gray.jpg' );

  B_average = faces_average ( B );

  figure ( 2 )
  clf
  imshow ( B_average );
  title ( 'Average Taylor Swift' );
  filename = 'taylor_average.jpg';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

%
%  Arnold Schwarzenegger
%
  C(:,:,1) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold01_gray.jpg' );
  C(:,:,2) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold02_gray.jpg' );
  C(:,:,3) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold03_gray.jpg' );
  C(:,:,4) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold04_gray.jpg' );
  C(:,:,5) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold05_gray.jpg' );
  C(:,:,6) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold06_gray.jpg' );
  C(:,:,7) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold07_gray.jpg' );
  C(:,:,8) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold08_gray.jpg' );
  C(:,:,9) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold09_gray.jpg' );
  C(:,:,10) = imread ( '../../datasets/faces_arnold_schwarzenegger/arnold10_gray.jpg' );

  C_average = faces_average ( C );

  figure ( 3 )
  clf
  imshow ( C_average );
  title ( 'Average Arnold Schwarzenegger' );
  filename = 'arnold_average.jpg';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Sylvester Stallone
%
  D(:,:,1) = imread ( '../../datasets/faces_sylvester_stallone/sylvester01_gray.jpg' );
  D(:,:,2) = imread ( '../../datasets/faces_sylvester_stallone/sylvester02_gray.jpg' );
  D(:,:,3) = imread ( '../../datasets/faces_sylvester_stallone/sylvester03_gray.jpg' );
  D(:,:,4) = imread ( '../../datasets/faces_sylvester_stallone/sylvester04_gray.jpg' );
  D(:,:,5) = imread ( '../../datasets/faces_sylvester_stallone/sylvester05_gray.jpg' );
  D(:,:,6) = imread ( '../../datasets/faces_sylvester_stallone/sylvester06_gray.jpg' );
  D(:,:,7) = imread ( '../../datasets/faces_sylvester_stallone/sylvester07_gray.jpg' );
  D(:,:,8) = imread ( '../../datasets/faces_sylvester_stallone/sylvester08_gray.jpg' );
  D(:,:,9) = imread ( '../../datasets/faces_sylvester_stallone/sylvester09_gray.jpg' );
  D(:,:,10) = imread ( '../../datasets/faces_sylvester_stallone/sylvester10_gray.jpg' );

  D_average = faces_average ( D );

  figure ( 4 )
  clf
  imshow ( D_average );
  title ( 'Average Sylvester Stallone' );
  filename = 'sylvester_average.jpg';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Show A1,            B1,            C1,            D1
%       A1_average,    B1_average,    C1_average,    D1_average
%       A1-A1_average, B1-B1_average, C1-C1_average, D1-D1_average
%
  figure ( 5 )
  clf
  sgtitle ( 'Images, Averages, Image-Average', 'Fontsize', 16 )
  subplot ( 3, 4, 1 )
  imshow ( A(:,:,1) )
  subplot ( 3, 4, 2 )
  imshow ( B(:,:,1) )
  subplot ( 3, 4, 3 )
  imshow ( C(:,:,1) )
  subplot ( 3, 4, 4 )
  imshow ( D(:,:,1) )
  subplot ( 3, 4, 5 )
  imshow ( A_average )
  subplot ( 3, 4, 6 )
  imshow ( B_average )
  subplot ( 3, 4, 7 )
  imshow ( C_average )
  subplot ( 3, 4, 8 )
  imshow ( D_average )
  subplot ( 3, 4, 9 )
  imshow ( A(:,:,1) - A_average )
  subplot ( 3, 4, 10 )
  imshow ( B(:,:,1) - B_average )
  subplot ( 3, 4, 11 )
  imshow ( C(:,:,1) - C_average )
  subplot ( 3, 4, 12 )
  imshow ( D(:,:,1) - D_average )
  filename = 'image_minus_average.jpg';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Angela Merkel.
%
  F(:,:,1) = imread ( '../../datasets/faces_angela_merkel/angela01_gray.jpg' );
  F(:,:,2) = imread ( '../../datasets/faces_angela_merkel/angela02_gray.jpg' );
  F(:,:,3) = imread ( '../../datasets/faces_angela_merkel/angela03_gray.jpg' );
  F(:,:,4) = imread ( '../../datasets/faces_angela_merkel/angela04_gray.jpg' );
  F(:,:,5) = imread ( '../../datasets/faces_angela_merkel/angela05_gray.jpg' );
  F(:,:,6) = imread ( '../../datasets/faces_angela_merkel/angela06_gray.jpg' );
  F(:,:,7) = imread ( '../../datasets/faces_angela_merkel/angela07_gray.jpg' );
  F(:,:,8) = imread ( '../../datasets/faces_angela_merkel/angela08_gray.jpg' );
  F(:,:,9) = imread ( '../../datasets/faces_angela_merkel/angela09_gray.jpg' );
  F(:,:,10) = imread ( '../../datasets/faces_angela_merkel/angela10_gray.jpg' );
  F(:,:,11) = imread ( '../../datasets/faces_angela_merkel/angela11_gray.jpg' );
  F(:,:,12) = imread ( '../../datasets/faces_angela_merkel/angela12_gray.jpg' );

  F_average = faces_average ( F );

  figure ( 6 )
  clf
  imshow ( F_average );
  title ( 'Average Angela Merkel' );
  filename = 'angela_average.jpg';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'FACES_AVERAGE_TEST:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../faces_average' );

  return
end