function gray = gray_uniform_noise ( gray, level )

%*****************************************************************************80
%
%% GRAY_UNIFORM_NOISE adds uniform noise to a grayscale image.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    17 March 2017
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, uint8 GRAY(:,:), the image.
%
%    Input, real LEVEL, the level of noise to add, between 0.0 (none)
%    and 1.0 (all).
%
%    Output, uint8 GRAY(:,:), the image with added noise.  A fraction of
%    about LEVEL of the pixels have been reset to a random value.
%
  [ m, n ] = size ( gray );

  r = rand ( m, n );

  i = find ( r <= level );
  n2 = length ( i );
  gray ( i ) = randi ( [ 0, 255 ], n2, 1 );

  return
end
