<commit_before>#include "common.h"

#include "itkRescaleIntensityImageFilter.h"
#include "itkNthElementImageAdaptor.h"

#include "haralick.h"

#include "image_loader.h"

typedef itk::RescaleIntensityImageFilter<ImageType, ImageType> RescaleFilter;
typedef typename itk::Statistics::ScalarImageToHaralickTextureFeaturesImageFilter< ImageType, double > ScalarImageToHaralickTextureFeaturesImageFilter;
typedef typename ScalarImageToHaralickTextureFeaturesImageFilter::OutputImageType HaralickImageType;

typedef itk::NthElementImageAdaptor< HaralickImageType, double > HaralickImageToScalarImageAdaptorType;
typedef itk::RescaleIntensityImageFilter< HaralickImageToScalarImageAdaptorType, ScalarHaralickImageType > ScalarHaralickImageRescaleFilter;

NormalizedHaralickImage::Pointer load_texture_image(const std::string filename, const unsigned int _posterizationLevel, const unsigned int _windowRadius)
{
  // Read the input image
  ImageType::Pointer image;
  try {
    image = ImageLoader::load(filename);
  } catch (ImageLoadingException & ex) {
    throw HaralickImageException(ex.what());
  }

  try {
    // Posterize the input image
    typename RescaleFilter::Pointer rescaler = RescaleFilter::New();
    rescaler->SetInput(image);
    rescaler->SetOutputMinimum(0);
    rescaler->SetOutputMaximum(_posterizationLevel);
    rescaler->Update();

    // Compute the haralick features
    typename ScalarImageToHaralickTextureFeaturesImageFilter::Pointer haralickImageComputer = ScalarImageToHaralickTextureFeaturesImageFilter::New();
    typename ScalarImageToHaralickTextureFeaturesImageFilter::RadiusType windowRadius; windowRadius.Fill(_windowRadius);
    haralickImageComputer->SetInput(rescaler->GetOutput());
    haralickImageComputer->SetWindowRadius(windowRadius);
    haralickImageComputer->SetNumberOfBinsPerAxis(_posterizationLevel);

    typename ScalarImageToHaralickTextureFeaturesImageFilter::OffsetType offset1 = {{0, 1}};
    typename ScalarImageToHaralickTextureFeaturesImageFilter::OffsetVectorType::Pointer offsetV = ScalarImageToHaralickTextureFeaturesImageFilter::OffsetVectorType::New();
    offsetV->push_back(offset1);
    haralickImageComputer->SetOffsets(offsetV);
    haralickImageComputer->Update();

    // Rescale haralick features
    ScalarHaralickImageToHaralickImageFilterType::Pointer imageToVectorImageFilter = ScalarHaralickImageToHaralickImageFilterType::New();

    #pragma omp parallel for
    for(int i = 0; i < 8; ++i)
    {
      HaralickImageToScalarImageAdaptorType::Pointer adaptor = HaralickImageToScalarImageAdaptorType::New();
      adaptor->SelectNthElement(i);
      adaptor->SetImage(haralickImageComputer->GetOutput());

      ScalarHaralickImageRescaleFilter::Pointer rescaler = ScalarHaralickImageRescaleFilter::New();
      rescaler->SetInput(adaptor);<commit_msg>When we works with N colors, the colors go from 0 to N-1. This is also 3D images...<commit_after>#include "common.h"

#include "itkRescaleIntensityImageFilter.h"
#include "itkNthElementImageAdaptor.h"

#include "haralick.h"

#include "image_loader.h"

#include "itkImageRegionIteratorWithIndex.h"

typedef itk::RescaleIntensityImageFilter<ImageType, ImageType> RescaleFilter;
typedef typename itk::Statistics::ScalarImageToHaralickTextureFeaturesImageFilter< ImageType, double > ScalarImageToHaralickTextureFeaturesImageFilter;
typedef typename ScalarImageToHaralickTextureFeaturesImageFilter::OutputImageType HaralickImageType;

typedef itk::NthElementImageAdaptor< HaralickImageType, double > HaralickImageToScalarImageAdaptorType;
typedef itk::RescaleIntensityImageFilter< HaralickImageToScalarImageAdaptorType, ScalarHaralickImageType > ScalarHaralickImageRescaleFilter;

NormalizedHaralickImage::Pointer load_texture_image(const std::string filename, const unsigned int _posterizationLevel, const unsigned int _windowRadius)
{
  // Read the input image
  ImageType::Pointer image;
  try {
    image = ImageLoader::load(filename);
  } catch (ImageLoadingException & ex) {
    throw HaralickImageException(ex.what());
  }

  try {
    // Posterize the input image
    typename RescaleFilter::Pointer rescaler = RescaleFilter::New();
    rescaler->SetInput(image);
    rescaler->SetOutputMinimum(0);
    rescaler->SetOutputMaximum(_posterizationLevel - 1);
    rescaler->Update();

    // Compute the haralick features
    typename ScalarImageToHaralickTextureFeaturesImageFilter::Pointer haralickImageComputer = ScalarImageToHaralickTextureFeaturesImageFilter::New();
    typename ScalarImageToHaralickTextureFeaturesImageFilter::RadiusType windowRadius; windowRadius.Fill(_windowRadius);
    haralickImageComputer->SetInput(rescaler->GetOutput());
    haralickImageComputer->SetWindowRadius(windowRadius);
    haralickImageComputer->SetNumberOfBinsPerAxis(_posterizationLevel);

    typename ScalarImageToHaralickTextureFeaturesImageFilter::OffsetType offset1 = {{1, 0, 0}};
    typename ScalarImageToHaralickTextureFeaturesImageFilter::OffsetVectorType::Pointer offsetV = ScalarImageToHaralickTextureFeaturesImageFilter::OffsetVectorType::New();
    offsetV->push_back(offset1);
    haralickImageComputer->SetOffsets(offsetV);
    haralickImageComputer->Update();

    // Rescale haralick features
    ScalarHaralickImageToHaralickImageFilterType::Pointer imageToVectorImageFilter = ScalarHaralickImageToHaralickImageFilterType::New();

    #pragma omp parallel for
    for(int i = 0; i < 8; ++i)
    {
      HaralickImageToScalarImageAdaptorType::Pointer adaptor = HaralickImageToScalarImageAdaptorType::New();
      adaptor->SelectNthElement(i);
      adaptor->SetImage(haralickImageComputer->GetOutput());

      ScalarHaralickImageRescaleFilter::Pointer rescaler = ScalarHaralickImageRescaleFilter::New();
      rescaler->SetInput(adaptor);
{'fraction_non_alphanumeric': 0.08623376623376623, 'fraction_numerical': 0.00329004329004329, 'mean_word_length': 7.383164005805515, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 41, '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': '7076042', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1656, 'n_words': 270}