<commit_before>#include "itkCommandLineArgumentParser.h"
#include "CommandLineArgumentHelper.h"

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkStatisticsImageFilter.h"
#include "itkInvertIntensityImageFilter.h"

/** This program inverts the intensity of an image:
 * new = max - old,
 * where max is the maximum of an image.
 */

//-------------------------------------------------------------------------------------

/** run: A macro to call a function. */
#define run( function, type, dim ) \
if ( ComponentTypeIn == #type && Dimension == dim ) \
{ \
    typedef itk::Image< type, dim > InputImageType; \
    function< InputImageType >( inputFileName, outputFileName ); \
}

//-------------------------------------------------------------------------------------

/** Declare InvertIntensity. */
template< class InputImageType >
void InvertIntensity(
  const std::string & inputFileName,
	const std::string & outputFileName );

/** Declare PrintHelp. */
void PrintHelp( void );

//-------------------------------------------------------------------------------------

int main( int argc, char ** argv )
{
  /** Check arguments for help. */
	if ( argc < 3 )
	{
		PrintHelp();
		return 1;
	}

	/** Create a command line argument parser. */
	itk::CommandLineArgumentParser::Pointer parser = itk::CommandLineArgumentParser::New();
	parser->SetCommandLineArguments( argc, argv );

	/** Get arguments. */
	std::string	inputFileName = "";
	bool retin = parser->GetCommandLineArgument( "-in", inputFileName );
  if ( !retin )
	{
		std::cerr << "ERROR: You should specify \"-in\"." << std::endl;
		return 1;
	}

	std::string	outputFileName = inputFileName.substr( 0, inputFileName.rfind( "." ) );
	outputFileName += "INVERTED.mhd";
	bool retout = parser->GetCommandLineArgument( "-out", outputFileName );

  /** Determine image properties. */
  std::string ComponentTypeIn = "short";
  std::string	PixelType; //we don't use this
  unsigned int Dimension = 2;
  unsigned int NumberOfComponents = 1;
  std::vector<unsigned int> imagesize( Dimension, 0 );
  int retgip = GetImageProperties(
    inputFileName,
    PixelType,
    ComponentTypeIn,
    Dimension,
    NumberOfComponents,
    imagesize );
  if ( retgip != 0 )
  {
    return 1;
  }

  /** Check for vector images. */
  if ( NumberOfComponents > 1 )
  { 
    std::cerr << "ERROR: The NumberOfComponents is larger than 1!" << std::endl;
    std::cerr << "Vector images are not supported." << std::endl;
    return 1; 
  }

	/** Get rid of the possible "_" in ComponentType. */
  ReplaceUnderscoreWithSpace( ComponentTypeIn );
	
	/** Run the program. */
	try
	{
    /** 2D. */
    run( InvertIntensity, char, 2 );
    run( InvertIntensity, unsigned char, 2 );
		run( InvertIntensity, short, 2 );
    run( InvertIntensity, unsigned short, 2 );
    run( InvertIntensity, float, 2 );
    run( InvertIntensity, double, 2 );

    /** 3D. */
    run( InvertIntensity, char, 3 );
    run( InvertIntensity, unsigned char, 3 );
		run( InvertIntensity, short, 3 );
    run( InvertIntensity, unsigned short, 3 );
    run( InvertIntensity, float, 3 );
    run( InvertIntensity, double, 3 );

	} // end run
  	catch ( itk::ExceptionObject &e )
	{
		std::cerr << "Caught ITK exception: " << e << std::endl;
		return 1;
	}
	
	/** End program. */
	return 0;

} // end main


	/**
	 * ******************* InvertIntensity *******************
	 *
	 * The resize function templated over the input pixel type.
	 */

template< class InputImageType >
void InvertIntensity( const std::string & inputFileName,
  const std::string & outputFileName )
{
	/** Some typedef's. */
  typedef typename InputImageType::PixelType                InputPixelType;
	typedef itk::ImageFileReader< InputImageType >						ReaderType;
	typedef itk::ImageFileWriter< InputImageType >						WriterType;
	typedef itk::StatisticsImageFilter< InputImageType >			StatisticsFilterType;
	typedef StatisticsFilterType::RealType							      RealType;
	typedef itk::InvertIntensityImageFilter< InputImageType >	InvertIntensityFilterType;
	
	/** Create reader. */
	ReaderType::Pointer reader = ReaderType::New();
	reader->SetFileName( inputFileName.c_str() );

	/** Create statistics filter. */
	StatisticsFilterType::Pointer statistics = StatisticsFilterType::New();
	statistics->SetInput( reader->GetOutput() );
	statistics->Update();

	/** Get all the output stuff. */
	InputPixelType max = statistics->GetMaximum();

	/** Create invert filter. */
	InvertIntensityFilterType::Pointer invertFilter = InvertIntensityFilterType::New();
	invertFilter->SetInput( reader->GetOutput() );
	invertFilter->SetMaximum( max );

	/** Create writer. */
	WriterType::Pointer writer = WriterType::New();
  writer->SetFileName( outputFileName.c_str() );
	writer->SetInput( invertFilter->GetOutput() );
  writer->Update();

} // end InvertIntensity()

	/**
	 * ******************* PrintHelp *******************<commit_msg>MSl:<commit_after>#include "itkCommandLineArgumentParser.h"
#include "CommandLineArgumentHelper.h"

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkStatisticsImageFilter.h"
#include "itkInvertIntensityImageFilter.h"

/** This program inverts the intensity of an image:
 * new = max - old,
 * where max is the maximum of an image.
 */

//-------------------------------------------------------------------------------------

/** run: A macro to call a function. */
#define run( function, type, dim ) \
if ( ComponentTypeIn == #type && Dimension == dim ) \
{ \
    typedef itk::Image< type, dim > InputImageType; \
    function< InputImageType >( inputFileName, outputFileName ); \
}

//-------------------------------------------------------------------------------------

/** Declare InvertIntensity. */
template< class InputImageType >
void InvertIntensity(
  const std::string & inputFileName,
	const std::string & outputFileName );

/** Declare PrintHelp. */
void PrintHelp( void );

//-------------------------------------------------------------------------------------

int main( int argc, char ** argv )
{
  /** Check arguments for help. */
	if ( argc < 3 )
	{
		PrintHelp();
		return 1;
	}

	/** Create a command line argument parser. */
	itk::CommandLineArgumentParser::Pointer parser = itk::CommandLineArgumentParser::New();
	parser->SetCommandLineArguments( argc, argv );

	/** Get arguments. */
	std::string	inputFileName = "";
	bool retin = parser->GetCommandLineArgument( "-in", inputFileName );
  if ( !retin )
	{
		std::cerr << "ERROR: You should specify \"-in\"." << std::endl;
		return 1;
	}

	std::string	outputFileName = inputFileName.substr( 0, inputFileName.rfind( "." ) );
	outputFileName += "INVERTED.mhd";
	bool retout = parser->GetCommandLineArgument( "-out", outputFileName );

  /** Determine image properties. */
  std::string ComponentTypeIn = "short";
  std::string	PixelType; //we don't use this
  unsigned int Dimension = 2;
  unsigned int NumberOfComponents = 1;
  std::vector<unsigned int> imagesize( Dimension, 0 );
  int retgip = GetImageProperties(
    inputFileName,
    PixelType,
    ComponentTypeIn,
    Dimension,
    NumberOfComponents,
    imagesize );
  if ( retgip != 0 )
  {
    return 1;
  }

  /** Check for vector images. */
  if ( NumberOfComponents > 1 )
  { 
    std::cerr << "ERROR: The NumberOfComponents is larger than 1!" << std::endl;
    std::cerr << "Vector images are not supported." << std::endl;
    return 1; 
  }

	/** Get rid of the possible "_" in ComponentType. */
  ReplaceUnderscoreWithSpace( ComponentTypeIn );
	
	/** Run the program. */
	try
	{
    /** 2D. */
    run( InvertIntensity, char, 2 );
    run( InvertIntensity, unsigned char, 2 );
		run( InvertIntensity, short, 2 );
    run( InvertIntensity, unsigned short, 2 );
    run( InvertIntensity, float, 2 );
    run( InvertIntensity, double, 2 );

    /** 3D. */
    run( InvertIntensity, char, 3 );
    run( InvertIntensity, unsigned char, 3 );
		run( InvertIntensity, short, 3 );
    run( InvertIntensity, unsigned short, 3 );
    run( InvertIntensity, float, 3 );
    run( InvertIntensity, double, 3 );

	} // end run
  	catch ( itk::ExceptionObject &e )
	{
		std::cerr << "Caught ITK exception: " << e << std::endl;
		return 1;
	}
	
	/** End program. */
	return 0;

} // end main


	/**
	 * ******************* InvertIntensity *******************
	 *
	 * The resize function templated over the input pixel type.
	 */

template< class InputImageType >
void InvertIntensity( const std::string & inputFileName,
  const std::string & outputFileName )
{
	/** Some typedef's. */
  typedef typename InputImageType::PixelType                InputPixelType;
	typedef itk::ImageFileReader< InputImageType >						ReaderType;
	typedef itk::ImageFileWriter< InputImageType >						WriterType;
	typedef itk::StatisticsImageFilter< InputImageType >			StatisticsFilterType;
	typedef typename StatisticsFilterType::RealType							      RealType;
	typedef itk::InvertIntensityImageFilter< InputImageType >	InvertIntensityFilterType;
	
	/** Create reader. */
	typename ReaderType::Pointer reader = ReaderType::New();
	reader->SetFileName( inputFileName.c_str() );

	/** Create statistics filter. */
	typename StatisticsFilterType::Pointer statistics = StatisticsFilterType::New();
	statistics->SetInput( reader->GetOutput() );
	statistics->Update();

	/** Get all the output stuff. */
	InputPixelType max = statistics->GetMaximum();

	/** Create invert filter. */
	typename InvertIntensityFilterType::Pointer invertFilter = InvertIntensityFilterType::New();
	invertFilter->SetInput( reader->GetOutput() );
	invertFilter->SetMaximum( max );

	/** Create writer. */
	typename WriterType::Pointer writer = WriterType::New();
  writer->SetFileName( outputFileName.c_str() );
	writer->SetInput( invertFilter->GetOutput() );
  writer->Update();

} // end InvertIntensity()

	/**
	 * ******************* PrintHelp *******************
{'fraction_non_alphanumeric': 0.19420319127449, 'fraction_numerical': 0.005655423146839022, 'mean_word_length': 3.0486508585445624, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2651540', 'n_tokens_mistral': 3052, 'n_tokens_neox': 2843, 'n_words': 761}