function image_quantization_test01 ( prefix, ext )

%*****************************************************************************80
%
%% IMAGE_QUANTIZATION_TEST01 tests GRAYSCALE_QUANTIZATION.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    04 February 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'IMAGE_QUANTIZATION_TEST01\n' );
  fprintf ( 1, '  IMAGE_QUANTIZATION_GRAYS uses KMEANS to choose\n' );
  fprintf ( 1, '  a small number of grays to display a grayscale image.\n' );
%
%  Read the image from a file.
%
  filename = [ prefix, '.', ext ];
  g = imread ( filename );
  [ m, n ] = size ( g );
%
%  FIGURE 1: The original image.
%
  figure ( 1 )
  imshow ( g );
  title ( 'Original image' )
  filename = [ prefix, '_256.png' ];
  print ( '-dpng', filename )
%
%  FIGURE 2: Grayscale histogram.
%
  p = double ( g );
  p = reshape ( p, m * n, 1 );

  figure ( 2 )
  hist ( p, 256 )
  title ( 'Histogram for original image' )
  filename = [ prefix, '_histogram.png' ];
  print ( '-dpng', filename );
%
%  FIGURE 3: Make a version using 16 grayscales.
%
  k = 16;
  g2 = image_quantization_gray ( g, k );

  figure ( 3 )
  imshow ( g2 )
  title_string = sprintf ( 'Image using %d shades', k );
  title ( title_string )
  filename = [ prefix, '_16.png' ];
  print ( '-dpng', filename );
%
%  FIGURE 4: Make a version with 4 grayscales.
%
  k = 4;
  g3 = image_quantization_gray ( g, k );

  figure ( 4 )
  imshow ( g3 )
  title_string = sprintf ( 'Image using %d shades', k );
  title ( title_string )
  filename = [ prefix, '_4.png' ];
  print ( '-dpng', filename );
%
%  FIGURE 5: Make a version with 2 grayscales.
%
  k = 2;
  g4 = image_quantization_gray ( g, k );

  figure ( 5 )
  imshow ( g4 )
  title_string = sprintf ( 'Image using %d shades', k );
  title ( title_string )
  filename = [ prefix, '_2.png' ];
  print ( '-dpng', filename );

  return
end
