<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: ImageCompareCommand.cxx, v $
  Language:  C++
  Date:      $Date: 2008-11-09 18:18:52 $
  Version:   $Revision: 1.12 $

  Copyright ( c ) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "itktubeDifferenceImageFilter.h"

#include <itkExtractImageFilter.h>
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
#include <itkRescaleIntensityImageFilter.h>

#include "ImageCompareCommandCLP.h"

// Description:
// Get the ComponentType and dimension of the image
void GetImageInformation( std::string fileName,
                          itk::ImageIOBase::IOComponentType &componentType,
                          unsigned int & dimension )
{
  // Find out the component type of the image in file
  typedef itk::ImageIOBase::IOComponentType  PixelType;

  itk::ImageIOBase::Pointer imageIO =
    itk::ImageIOFactory::CreateImageIO( fileName.c_str(),
                                        itk::ImageIOFactory::ReadMode );
  if( !imageIO )
    {
    std::cerr << "NO IMAGEIO WAS FOUND" << std::endl;
    return;
    }

  // Now that we found the appropriate ImageIO class, ask it to
  // read the meta data from the image file.
  imageIO->SetFileName( fileName.c_str() );
  imageIO->ReadImageInformation();

  componentType = imageIO->GetComponentType();
  dimension = imageIO->GetNumberOfDimensions();
}

template< unsigned int VDimension >
int RegressionTestImage( const char *, const char *, bool, bool, double,
  int, int, bool, const char * );

int main( int argc, char * argv[] )
{
  int bestBaselineStatus = 2001;
  bool writeOutputImage = false;
  PARSE_ARGS;

  std::string bestBaselineFilename;
  itk::ImageIOBase::IOComponentType cType = itk::ImageIOBase::UCHAR;
  unsigned int dims = 0;

  GetImageInformation( testImageFilename, cType, dims );

  try
    {
    typedef std::vector< std::string >::const_iterator  nameIterator;
    nameIterator baselineImageItr = baselineImageFilenames.begin();
    while( baselineImageItr != baselineImageFilenames.end() )
      {
      int currentStatus = 0;
      if( dims == 2 )
        {
        currentStatus = RegressionTestImage<2>(
          testImageFilename.c_str(), baselineImageItr->c_str(),
          false, false, toleranceIntensity, toleranceRadius,
          toleranceNumberOfPixels, false, outputImageFilename.c_str() );
        }
      else
        {
        currentStatus = RegressionTestImage<3>(
          testImageFilename.c_str(), baselineImageItr->c_str(),
          false, false, toleranceIntensity, toleranceRadius,
          toleranceNumberOfPixels, false, outputImageFilename.c_str() );
        }
      if( currentStatus < bestBaselineStatus )
        {
        bestBaselineStatus = currentStatus;
        bestBaselineFilename = *baselineImageItr;
        }
      if( bestBaselineStatus == 0 )
        {
        break;
        }
      ++baselineImageItr;
      }

    // generate images of our closest match
    if( bestBaselineStatus == 0 )
      {
      if( dims == 2 )
        {
        RegressionTestImage<2>(
          testImageFilename.c_str(),
          bestBaselineFilename.c_str(), true, false,
          toleranceIntensity, toleranceRadius, toleranceNumberOfPixels,
          writeOutputImage, outputImageFilename.c_str() );
        }
      else
        {
        RegressionTestImage<3>(
          testImageFilename.c_str(),
          bestBaselineFilename.c_str(), true, false,
          toleranceIntensity, toleranceRadius, toleranceNumberOfPixels,
          writeOutputImage, outputImageFilename.c_str() );
        }
      }
    else
      {
      if( dims == 2 )
        {
        RegressionTestImage<2>(
          testImageFilename.c_str(),
          bestBaselineFilename.c_str(), true, true,
          toleranceIntensity, toleranceRadius, toleranceNumberOfPixels,<commit_msg>STYLE: Reduce writeOutputImage scope in ImageCompareCommand.<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: ImageCompareCommand.cxx, v $
  Language:  C++
  Date:      $Date: 2008-11-09 18:18:52 $
  Version:   $Revision: 1.12 $

  Copyright ( c ) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "itktubeDifferenceImageFilter.h"

#include <itkExtractImageFilter.h>
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
#include <itkRescaleIntensityImageFilter.h>

#include "ImageCompareCommandCLP.h"

// Description:
// Get the ComponentType and dimension of the image
void GetImageInformation( std::string fileName,
                          itk::ImageIOBase::IOComponentType &componentType,
                          unsigned int & dimension )
{
  // Find out the component type of the image in file
  typedef itk::ImageIOBase::IOComponentType  PixelType;

  itk::ImageIOBase::Pointer imageIO =
    itk::ImageIOFactory::CreateImageIO( fileName.c_str(),
                                        itk::ImageIOFactory::ReadMode );
  if( !imageIO )
    {
    std::cerr << "NO IMAGEIO WAS FOUND" << std::endl;
    return;
    }

  // Now that we found the appropriate ImageIO class, ask it to
  // read the meta data from the image file.
  imageIO->SetFileName( fileName.c_str() );
  imageIO->ReadImageInformation();

  componentType = imageIO->GetComponentType();
  dimension = imageIO->GetNumberOfDimensions();
}

template< unsigned int VDimension >
int RegressionTestImage( const char *, const char *, bool, bool, double,
  int, int, bool, const char * );

int main( int argc, char * argv[] )
{
  int bestBaselineStatus = 2001;
  PARSE_ARGS;

  std::string bestBaselineFilename;
  itk::ImageIOBase::IOComponentType cType = itk::ImageIOBase::UCHAR;
  unsigned int dims = 0;

  GetImageInformation( testImageFilename, cType, dims );

  try
    {
    typedef std::vector< std::string >::const_iterator  nameIterator;
    nameIterator baselineImageItr = baselineImageFilenames.begin();
    while( baselineImageItr != baselineImageFilenames.end() )
      {
      int currentStatus = 0;
      if( dims == 2 )
        {
        currentStatus = RegressionTestImage<2>(
          testImageFilename.c_str(), baselineImageItr->c_str(),
          false, false, toleranceIntensity, toleranceRadius,
          toleranceNumberOfPixels, false, outputImageFilename.c_str() );
        }
      else
        {
        currentStatus = RegressionTestImage<3>(
          testImageFilename.c_str(), baselineImageItr->c_str(),
          false, false, toleranceIntensity, toleranceRadius,
          toleranceNumberOfPixels, false, outputImageFilename.c_str() );
        }
      if( currentStatus < bestBaselineStatus )
        {
        bestBaselineStatus = currentStatus;
        bestBaselineFilename = *baselineImageItr;
        }
      if( bestBaselineStatus == 0 )
        {
        break;
        }
      ++baselineImageItr;
      }

    bool writeOutputImage = false;
    // generate images of our closest match
    if( bestBaselineStatus == 0 )
      {
      if( dims == 2 )
        {
        RegressionTestImage<2>(
          testImageFilename.c_str(),
          bestBaselineFilename.c_str(), true, false,
          toleranceIntensity, toleranceRadius, toleranceNumberOfPixels,
          writeOutputImage, outputImageFilename.c_str() );
        }
      else
        {
        RegressionTestImage<3>(
          testImageFilename.c_str(),
          bestBaselineFilename.c_str(), true, false,
          toleranceIntensity, toleranceRadius, toleranceNumberOfPixels,
          writeOutputImage, outputImageFilename.c_str() );
        }
      }
    else
      {
      if( dims == 2 )
        {
        RegressionTestImage<2>(
          testImageFilename.c_str(),
          bestBaselineFilename.c_str(), true, true,
          toleranceIntensity, toleranceRadius, toleranceNumberOfPixels,
{'fraction_non_alphanumeric': 0.12544596616411555, 'fraction_numerical': 0.007595810795258373, 'mean_word_length': 2.969849246231156, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6796445', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2354, 'n_words': 576}