<commit_before>#ifndef __itkScalarImageToHaralickTextureFeaturesImageFilter_h
#define __itkScalarImageToHaralickTextureFeaturesImageFilter_h

#include "itkScalarImageToLocalHaralickTextureFeaturesFilter.h"
#include "itkVectorImage.h"
#include "itkImageRegionIteratorWithIndex.h"

namespace itk
{
namespace Statistics
{

template< class TInputImageType, class TOutputPixelType >
class ITK_EXPORT ScalarImageToHaralickTextureFeaturesImageFilter:
  public ImageToImageFilter< TInputImageType, VectorImage< TOutputPixelType, ::itk::GetImageDimension< TInputImageType >::ImageDimension > >
{
public:
  /** Standard typedefs */
  typedef ScalarImageToHaralickTextureFeaturesImageFilter   Self;
  typedef TInputImageType                                   InputImageType;
  typedef TOutputPixelType                                  OutputPixelType;

  itkStaticConstMacro(ImageDimension, unsigned int, ::itk::GetImageDimension< InputImageType >::ImageDimension);

  typedef VectorImage< OutputPixelType, itkGetStaticConstMacro(ImageDimension) >   OutputImageType;

  typedef ImageToImageFilter< InputImageType, OutputImageType >   Superclass;
  typedef SmartPointer< Self >                                    Pointer;
  typedef SmartPointer< const Self >                              ConstPointer;

  typedef typename InputImageType::PixelType    InputPixelType;
  typedef ::itk::Size< itkGetStaticConstMacro(ImageDimension) >    RadiusType;

  typedef ScalarImageToLocalHaralickTextureFeaturesFilter< InputImageType, OutputPixelType > LocalHaralickComputer;

  typedef typename LocalHaralickComputer::OffsetType         OffsetType;
  typedef typename LocalHaralickComputer::OffsetVectorType   OffsetVectorType;

  /** Run-time type information (and related methods). */
  itkTypeMacro(ScalarImageToHaralickTextureFeaturesImageFilter, ImageToImageFilter);

  /** standard New() method support */
  itkNewMacro(Self);

  ScalarImageToHaralickTextureFeaturesImageFilter()
  {
    this->SetNumberOfRequiredInputs(1);
    this->SetNumberOfRequiredOutputs(1);

    this->m_LocalHaralickComputer = LocalHaralickComputer::New();

    //this->ProcessObject::SetOutput(this->MakeOutput
  }

  virtual void GenerateInputRequestedRegion() throw( InvalidRequestedRegionError )
  {
    typename InputImageType::Pointer inputPtr =
      const_cast< InputImageType * >( this->GetInput() );

    if ( !inputPtr )
      return;

    typename InputImageType::RegionType inputRequestedRegion;
    inputRequestedRegion = inputPtr->GetRequestedRegion();

    // pad the input requested region by the operator radius
    inputRequestedRegion.PadByRadius(m_WindowRadius);

    // crop the input requested region at the input's largest possible region
    if ( inputRequestedRegion.Crop( inputPtr->GetLargestPossibleRegion() ) )
      {
      inputPtr->SetRequestedRegion(inputRequestedRegion);
      return;
      }
    else
      {
      // Couldn't crop the region (requested region is outside the largest
      // possible region).  Throw an exception.

      // store what we tried to request (prior to trying to crop)
      inputPtr->SetRequestedRegion(inputRequestedRegion);

      // build an exception
      InvalidRequestedRegionError e(__FILE__, __LINE__);
      e.SetLocation(ITK_LOCATION);
      e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
      e.SetDataObject(inputPtr);
      throw e;
      }
  }

  void GenerateOutputInformation(void)
  {
    // Override the method in itkImageSource, so we can set the vector length of
    // the output itk::VectorImage
    this->Superclass::GenerateOutputInformation();

    OutputImageType *output = this->GetOutput();
    output->SetNumberOfComponentsPerPixel( 8 );
  }

  void SetInput(const InputImageType *image)
  {
    this->SetNthInput( 0, const_cast< InputImageType * >( image ) );
  }

  itkSetMacro(WindowRadius, RadiusType);
  itkGetConstMacro(WindowRadius, RadiusType);

  inline void SetOffset(const OffsetType offset)
  {
    this->m_LocalHaralickComputer->SetOffset(offset);
  }

  inline void SetOffsets(const OffsetVectorType * offsets)
  {
    this->m_LocalHaralickComputer->SetOffsets(offsets);
  }

  inline const OffsetVectorType* GetOffsets()
  {
    return this->m_LocalHaralickComputer->GetOffsets();
  }


  inline void SetNumberOfBinsPerAxis(const unsigned char size)
  {
    this->m_LocalHaralickComputer->SetNumberOfBinsPerAxis(size);
  }

  inline const unsigned char GetNumberOfBinsPerAxis()
  {
    return this->m_LocalHaralickComputer->GetNumberOfBinsPerAxis();
  }

  void GenerateData(void)
  {
    itkDebugMacro( << "GenerateData() called");
    const InputImageType *input = this->GetInput();
    OutputImageType *output = this->GetOutput();

    this->m_LocalHaralickComputer->SetInput(input);

    typename InputImageType::RegionType windowRegion, requestedRegion = output->GetRequestedRegion();
    typename InputImageType::IndexType windowIndex;
    typename InputImageType::SizeType windowSize;

    for(unsigned int i = 0; i < itkGetStaticConstMacro(ImageDimension); ++i)
      {
      windowSize.SetElement(i, (m_WindowRadius.GetElement(i) << 1) + 1);
      }

    typedef itk::VariableLengthVector<double> VariableVectorType;
    VariableVectorType features;
    features.SetSize(8);

    output->SetBufferedRegion( output->GetRequestedRegion() );
    output->Allocate();

    ImageRegionConstIteratorWithIndex< InputImageType > imageIterator(input, requestedRegion);
    ImageRegionIteratorWithIndex< OutputImageType > outputIterator(output, requestedRegion);
    imageIterator.GoToBegin();
    outputIterator.GoToBegin();
    while(!imageIterator.IsAtEnd())
    {
      windowIndex = imageIterator.GetIndex();
      windowIndex -= m_WindowRadius;

      windowRegion.SetIndex(windowIndex);
      windowRegion.SetSize(windowSize);
      windowRegion.Crop(requestedRegion);

      itkDebugMacro( << "Processing Region: " << std::endl << windowRegion);

      this->m_LocalHaralickComputer->SetRegionOfInterest(windowRegion);
      this->m_LocalHaralickComputer->Update();

      features[0] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::Energy);
      features[1] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::Entropy);
      features[2] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::Correlation);
      features[3] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::InverseDifferenceMoment);
      features[4] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::Inertia);
      features[5] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::ClusterShade);
      features[6] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::ClusterProminence);
      features[7] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::HaralickCorrelation);
<commit_msg>Now use Image< FixedArray<> in ScalarImageToHaralickTextureFeaturesImage.<commit_after>#ifndef __itkScalarImageToHaralickTextureFeaturesImageFilter_h
#define __itkScalarImageToHaralickTextureFeaturesImageFilter_h

#include "itkScalarImageToLocalHaralickTextureFeaturesFilter.h"
#include "itkImageRegionIteratorWithIndex.h"

namespace itk
{
namespace Statistics
{

template< class TInputImageType, class TFeatureType >
class ITK_EXPORT ScalarImageToHaralickTextureFeaturesImageFilter:
  public ImageToImageFilter< TInputImageType, Image< FixedArray< TFeatureType, 8 >, ::itk::GetImageDimension< TInputImageType >::ImageDimension > >
{
public:
  /** Standard typedefs */
  typedef ScalarImageToHaralickTextureFeaturesImageFilter   Self;
  typedef TInputImageType                                   InputImageType;
  typedef TFeatureType                                      FeatureType;
  typedef FixedArray< TFeatureType, 8 >                     OutputPixelType;

  itkStaticConstMacro(ImageDimension, unsigned int, ::itk::GetImageDimension< InputImageType >::ImageDimension);

  typedef Image< OutputPixelType, itkGetStaticConstMacro(ImageDimension) >   OutputImageType;

  typedef ImageToImageFilter< InputImageType, OutputImageType >   Superclass;
  typedef SmartPointer< Self >                                    Pointer;
  typedef SmartPointer< const Self >                              ConstPointer;

  typedef typename InputImageType::PixelType    InputPixelType;
  typedef ::itk::Size< itkGetStaticConstMacro(ImageDimension) >    RadiusType;

  typedef ScalarImageToLocalHaralickTextureFeaturesFilter< InputImageType, FeatureType > LocalHaralickComputer;

  typedef typename LocalHaralickComputer::OffsetType         OffsetType;
  typedef typename LocalHaralickComputer::OffsetVectorType   OffsetVectorType;

  /** Run-time type information (and related methods). */
  itkTypeMacro(ScalarImageToHaralickTextureFeaturesImageFilter, ImageToImageFilter);

  /** standard New() method support */
  itkNewMacro(Self);

  ScalarImageToHaralickTextureFeaturesImageFilter()
  {
    this->SetNumberOfRequiredInputs(1);
    this->SetNumberOfRequiredOutputs(1);

    RadiusType defaultRadius;
    defaultRadius.Fill(0);
    defaultRadius[0] = 1;
    this->m_WindowRadius = defaultRadius;

    this->m_LocalHaralickComputer = LocalHaralickComputer::New();

    //this->ProcessObject::SetOutput(this->MakeOutput
  }

  virtual void GenerateInputRequestedRegion() throw( InvalidRequestedRegionError )
  {
    typename InputImageType::Pointer inputPtr =
      const_cast< InputImageType * >( this->GetInput() );

    if ( !inputPtr )
      return;

    typename InputImageType::RegionType inputRequestedRegion;
    inputRequestedRegion = inputPtr->GetRequestedRegion();

    // pad the input requested region by the operator radius
    inputRequestedRegion.PadByRadius(m_WindowRadius);

    // crop the input requested region at the input's largest possible region
    if ( inputRequestedRegion.Crop( inputPtr->GetLargestPossibleRegion() ) )
      {
      inputPtr->SetRequestedRegion(inputRequestedRegion);
      return;
      }
    else
      {
      // Couldn't crop the region (requested region is outside the largest
      // possible region).  Throw an exception.

      // store what we tried to request (prior to trying to crop)
      inputPtr->SetRequestedRegion(inputRequestedRegion);

      // build an exception
      InvalidRequestedRegionError e(__FILE__, __LINE__);
      e.SetLocation(ITK_LOCATION);
      e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
      e.SetDataObject(inputPtr);
      throw e;
      }
  }

  void GenerateOutputInformation(void)
  {
    // Override the method in itkImageSource, so we can set the vector length of
    // the output itk::VectorImage
    this->Superclass::GenerateOutputInformation();

    //OutputImageType *output = this->GetOutput();
    //output->SetNumberOfComponentsPerPixel( 8 );
  }

  void SetInput(const InputImageType *image)
  {
    this->SetNthInput( 0, const_cast< InputImageType * >( image ) );
  }

  itkSetMacro(WindowRadius, RadiusType);
  itkGetConstMacro(WindowRadius, RadiusType);

  inline void SetOffset(const OffsetType offset)
  {
    this->m_LocalHaralickComputer->SetOffset(offset);
  }

  inline void SetOffsets(const OffsetVectorType * offsets)
  {
    this->m_LocalHaralickComputer->SetOffsets(offsets);
  }

  inline const OffsetVectorType* GetOffsets()
  {
    return this->m_LocalHaralickComputer->GetOffsets();
  }


  inline void SetNumberOfBinsPerAxis(const unsigned char size)
  {
    this->m_LocalHaralickComputer->SetNumberOfBinsPerAxis(size);
  }

  inline const unsigned char GetNumberOfBinsPerAxis()
  {
    return this->m_LocalHaralickComputer->GetNumberOfBinsPerAxis();
  }

  void GenerateData(void)
  {
    itkDebugMacro( << "GenerateData() called");
    const InputImageType *input = this->GetInput();
    OutputImageType *output = this->GetOutput();

    this->m_LocalHaralickComputer->SetInput(input);

    typename InputImageType::RegionType windowRegion, requestedRegion = output->GetRequestedRegion();
    typename InputImageType::IndexType windowIndex;
    typename InputImageType::SizeType windowSize;

    for(unsigned int i = 0; i < itkGetStaticConstMacro(ImageDimension); ++i)
      {
      windowSize.SetElement(i, (m_WindowRadius.GetElement(i) << 1) + 1);
      }

    /*
    typedef itk::VariableLengthVector<double> VariableVectorType;
    VariableVectorType features;
    features.SetSize(8);
    */
    OutputPixelType features;

    output->SetBufferedRegion( output->GetRequestedRegion() );
    output->Allocate();

    ImageRegionConstIteratorWithIndex< InputImageType > imageIterator(input, requestedRegion);
    ImageRegionIteratorWithIndex< OutputImageType > outputIterator(output, requestedRegion);
    imageIterator.GoToBegin();
    outputIterator.GoToBegin();
    while(!imageIterator.IsAtEnd())
    {
      windowIndex = imageIterator.GetIndex();
      windowIndex -= m_WindowRadius;

      windowRegion.SetIndex(windowIndex);
      windowRegion.SetSize(windowSize);
      windowRegion.Crop(requestedRegion);

      itkDebugMacro( << "Processing Region: " << std::endl << windowRegion);

      this->m_LocalHaralickComputer->SetRegionOfInterest(windowRegion);
      this->m_LocalHaralickComputer->Update();

      features[0] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::Energy);
      features[1] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::Entropy);
      features[2] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::Correlation);
      features[3] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::InverseDifferenceMoment);
      features[4] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::Inertia);
      features[5] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::ClusterShade);
      features[6] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::ClusterProminence);
      features[7] = this->m_LocalHaralickComputer->GetFeature(LocalHaralickComputer::HaralickFeaturesComputer::HaralickCorrelation);

{'fraction_non_alphanumeric': 0.09142896513710899, 'fraction_numerical': 0.002549262780763401, 'mean_word_length': 4.645663166083236, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6741883', 'n_tokens_mistral': 4215, 'n_tokens_neox': 4001, 'n_words': 729}