function bwlabel_test ( )

%*****************************************************************************80
%
%% bwlabel_test() tests bwlabel().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 July 2022
%
%  Author:
%
%    Original MATLAB code from the Mathworks.
%    Modifications by John Burkardt
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'bwlabel_test():\n' );
  fprintf ( 1, '  bwlabel() groups binary matrix data into clusters.\n' );

  bw = logical ( ...
    [ 1, 1, 0, 0, 0, 1, 0, 0; ...
      1, 1, 1, 0, 1, 1, 0, 0; ...
      1, 1, 1, 0, 1, 1, 0, 0; ...
      0, 1, 1, 0, 0, 0, 1, 0; ...
      0, 0, 1, 0, 0, 0, 1, 0; ...
      1, 0, 1, 0, 0, 0, 1, 0; ...
      1, 1, 1, 1, 0, 1, 1, 1; ...
      1, 1, 0, 0, 0, 0, 0, 0 ] ...
  );
%
%  Find clusters using N/S/E/W connections.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Clusters using 4-way connectivity:\n' );
  label = bwlabel ( bw, 4 )

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Elements of cluster labeled #2:\n' );
  [ r, c ] = find ( label == 2 );
  rc = [ r, c ]
%
%  Find clusters using NW/N/NE/W/E/SW/S/SE connections.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Clusters using 8-way connectivity:\n' );
  label = bwlabel ( bw, 8 )

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Elements of cluster labeled #2:\n' );
  [ r, c ] = find ( label == 2 );
  rc = [ r, c ]
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'bwlabel_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

