<commit_before>#include "log4cxx/logger.h"
#include "log4cxx/consoleappender.h"
#include "log4cxx/patternlayout.h"
#include "log4cxx/basicconfigurator.h"

#include <boost/program_options.hpp>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkVectorImageToImageAdaptor.h"
#include "itkComposeImageFilter.h"

#include "datatypes.h"

#include "image_loader.h"

namespace po = boost::program_options;

typedef itk::ImageFileReader< OutputImageType > ImageReader;
typedef itk::ImageFileWriter< OutputImageType > ImageWriter;
typedef itk::VectorImageToImageAdaptor< typename OutputImageType::PixelType::ValueType, OutputImageType::ImageDimension > SingleChannelAdaptor;
typedef itk::ComposeImageFilter< SingleChannelAdaptor, OutputImageType > ChannelComposer;

std::ostream &operator<<(std::ostream &out, std::vector< int >& t)
{
	std::copy(t.begin(), t.end(), std::ostream_iterator<int>(out, ", ") );

	return out;
}

class out_of_range_predicate
{
public:
	out_of_range_predicate(const int l, const int h): lower_bound(l), higher_bound(h) {}
	bool operator()(const int v) { return (v < lower_bound) || (v > higher_bound); }
private:
	int lower_bound, higher_bound;
};

int main(int argc, char** argv)
{
	log4cxx::BasicConfigurator::configure(
			log4cxx::AppenderPtr(new log4cxx::ConsoleAppender(
					log4cxx::LayoutPtr(new log4cxx::PatternLayout("\%-5p - [%c] - \%m\%n")),
					log4cxx::ConsoleAppender::getSystemErr()
					)
				)
			);

	log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("main"));

	std::string input_image_path;
	std::string output_image_path;
	std::vector< int > channels_to_keep;
	std::vector< int > channels_to_remove;

	po::options_description main_options("Main options");

	main_options.add_options()
		("help,h",
			"Produce help message")
		("input-image,i",
			po::value< std::string >(&input_image_path)->required(),
			"Input image (required)")
		("output-image,o",
			po::value< std::string >(&output_image_path)->required(),
			"Ouput image (required)")
		("keep,k",
			po::value< std::vector< int > >(&channels_to_keep)->multitoken(),
			"Channels to keep")
		("remove,r",
			po::value< std::vector< int > >(&channels_to_remove)->multitoken(),
			"Channels to remove")
		;

	po::variables_map vm;

	try {
		po::parsed_options recognized_main_options = po::command_line_parser(argc, argv).options(main_options).run();

		std::vector< po::basic_option< char > >::iterator it;

		po::store(recognized_main_options, vm);

		// Handling --help before notify() in order to allow ->required()
		// http://stackoverflow.com/questions/5395503/required-and-optional-arguments-using-boost-library-program-options#answer-5517755
		if (vm.count("help")) {
			std::cerr << "Usage: " << argv[0] << " [options]" << std::endl;
			std::cerr << main_options;
			return 0;
		}

		vm.notify();
	} catch(po::error &err) {
		LOG4CXX_FATAL(logger, err.what());
		return -1;
	}

	LOG4CXX_INFO(logger, "Input image: " << input_image_path);
	LOG4CXX_INFO(logger, "Output image: " << output_image_path);<commit_msg>Add some useful comments.<commit_after>#include "log4cxx/logger.h"
#include "log4cxx/consoleappender.h"
#include "log4cxx/patternlayout.h"
#include "log4cxx/basicconfigurator.h"

#include <boost/program_options.hpp>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkVectorImageToImageAdaptor.h"
#include "itkComposeImageFilter.h"

#include "datatypes.h"

#include "image_loader.h"

namespace po = boost::program_options;

typedef itk::ImageFileReader< OutputImageType > ImageReader;
typedef itk::ImageFileWriter< OutputImageType > ImageWriter;
typedef itk::VectorImageToImageAdaptor< typename OutputImageType::PixelType::ValueType, OutputImageType::ImageDimension > SingleChannelAdaptor;
typedef itk::ComposeImageFilter< SingleChannelAdaptor, OutputImageType > ChannelComposer;

std::ostream &operator<<(std::ostream &out, std::vector< int >& t)
{
	std::copy(t.begin(), t.end(), std::ostream_iterator<int>(out, ", ") );

	return out;
}

class out_of_range_predicate
{
public:
	out_of_range_predicate(const int l, const int h): lower_bound(l), higher_bound(h) {}
	bool operator()(const int v) { return (v < lower_bound) || (v > higher_bound); }
private:
	int lower_bound, higher_bound;
};

int main(int argc, char** argv)
{
	log4cxx::BasicConfigurator::configure(
			log4cxx::AppenderPtr(new log4cxx::ConsoleAppender(
					log4cxx::LayoutPtr(new log4cxx::PatternLayout("\%-5p - [%c] - \%m\%n")),
					log4cxx::ConsoleAppender::getSystemErr()
					)
				)
			);

	log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("main"));

	std::string input_image_path;
	std::string output_image_path;
	std::vector< int > channels_to_keep;
	std::vector< int > channels_to_remove;

	po::options_description main_options("Main options");

	main_options.add_options()
		("help,h",
			"Produce help message")
		("input-image,i",
			po::value< std::string >(&input_image_path)->required(),
			"Input image (required)")
		("output-image,o",
			po::value< std::string >(&output_image_path)->required(),
			"Ouput image (required)")
		("keep,k",
			po::value< std::vector< int > >(&channels_to_keep)->multitoken(),
			"Channels to keep (1-based)")
		("remove,r",
			po::value< std::vector< int > >(&channels_to_remove)->multitoken(),
			"Channels to remove (1-based)")
		;

	po::variables_map vm;

	try {
		po::parsed_options recognized_main_options = po::command_line_parser(argc, argv).options(main_options).run();

		std::vector< po::basic_option< char > >::iterator it;

		po::store(recognized_main_options, vm);

		// Handling --help before notify() in order to allow ->required()
		// http://stackoverflow.com/questions/5395503/required-and-optional-arguments-using-boost-library-program-options#answer-5517755
		if (vm.count("help")) {
			std::cerr << "Usage: " << argv[0] << " [options]" << std::endl;
			std::cerr << main_options;
			return 0;
		}

		vm.notify();
	} catch(po::error &err) {
		LOG4CXX_FATAL(logger, err.what());
		return -1;
	}

	LOG4CXX_INFO(logger, "Input image: " << input_image_path);
	LOG4CXX_INFO(logger, "Output image: " << output_image_path);
{'fraction_non_alphanumeric': 0.16266202971862156, 'fraction_numerical': 0.010749288650015808, 'mean_word_length': 6.03781979977753, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 59, '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': '4508710', 'n_tokens_mistral': 2404, 'n_tokens_neox': 2219, 'n_words': 408}