original_docstring: Main function that runs histogram equalization on an image.
docstring: Main function that runs histogram equalization on an image.
docstring_tokens: Main function that runs histogram equalization on an image .
code: def main():
      """Main function that runs histogram equalization on an image."""
      import argparse
      import os.path
      import re
      import hist._cmd_line_util as cui
  
      # Extra imports to make sure everything is available now
      import numpy, scipy.ndimage # pylint: disable=unused-import, multiple-imports
  
      parser = argparse.ArgumentParser(prog='python3 -m hist',
                                       description='Perform histogram equalization on an image')
      cui.add_input_image(parser)
      parser.add_argument('output', nargs='?',
                          help='output image file, defaults to input file name with _out before '
                          'the extension')
      cui.add_method_arg(parser)
      cui.add_kwargs_arg(parser)
      parser.add_argument('--nbins', '-n', type=int, default=256, metavar='N',
                          help='number of bins in the intermediate histogram, default is 256')
      args = parser.parse_args()
  
      # Load image
      im = cui.open_input_image(args)
  
      # Run HE
      if args.method == 'classic':
          out = histeq(im, args.nbins, **dict(args.kwargs))
      else:
          out = histeq_exact(im, args.nbins, method=args.method, **dict(args.kwargs))
  
      # Save (if not testing)
      filename = args.output
      if filename == '': return # hidden feature for "testing" mode, no saving
      if filename is None:
          if os.path.isdir(args.input):
              filename = args.input + '_out'
          elif os.path.exists(args.input) and ('?' in args.input or '*' in args.input or
                                               ('[' in args.input and ']' in args.input)):
              filename = re.sub(r'\*|\?|\[.+\]', '#', args.input)
          elif args.input.lower().endswith('.npy.gz'):
              filename = args.input[:-7] + '_out' + args.input[-7:]
          else:
              filename = '_out'.join(os.path.splitext(args.input))
      __save(filename, out)
code_tokens: def main ( ) : import argparse import os . path import re import hist . _cmd_line_util as cui import numpy , scipy . ndimage parser = argparse . ArgumentParser ( prog = 'python3 -m hist' , description = 'Perform histogram equalization on an image' ) cui . add_input_image ( parser ) parser . add_argument ( 'output' , nargs = '?' , help = 'output image file, defaults to input file name with _out before ' 'the extension' ) cui . add_method_arg ( parser ) cui . add_kwargs_arg ( parser ) parser . add_argument ( '--nbins' , '-n' , type = int , default = 256 , metavar = 'N' , help = 'number of bins in the intermediate histogram, default is 256' ) args = parser . parse_args ( ) im = cui . open_input_image ( args ) if args . method == 'classic' : out = histeq ( im , args . nbins , ** dict ( args . kwargs ) ) else : out = histeq_exact ( im , args . nbins , method = args . method , ** dict ( args . kwargs ) ) filename = args . output if filename == '' : return if filename is None : if os . path . isdir ( args . input ) : filename = args . input + '_out' elif os . path . exists ( args . input ) and ( '?' in args . input or '*' in args . input or ( '[' in args . input and ']' in args . input ) ) : filename = re . sub ( r'\*|\?|\[.+\]' , '#' , args . input ) elif args . input . lower ( ) . endswith ( '.npy.gz' ) : filename = args . input [ : - 7 ] + '_out' + args . input [ - 7 : ] else : filename = '_out' . join ( os . path . splitext ( args . input ) ) __save ( filename , out )
short_docstring: Main function that runs histogram equalization on an image.
short_docstring_tokens: Main function that runs histogram equalization on an image .
comment: """Main function that runs histogram equalization on an image."""$SEP$# Extra imports to make sure everything is available now$SEP$# pylint: disable=unused-import, multiple-imports$SEP$# Load image$SEP$# Run HE$SEP$# Save (if not testing)$SEP$# hidden feature for "testing" mode, no saving