<commit_before>/*=========================================================================
 *
 *  Copyright <NAME> 2011 <EMAIL>
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#ifndef PIXELDIFFERENCE_H
#define PIXELDIFFERENCE_H

struct FullPixelDifference
{
  FullPixelDifference(typename FloatVectorImageType::PixelType& examplePixel)
  {
    this->NumberOfComponentsPerPixel = examplePixel.GetNumberOfElements();
    //std::cout << "FullPixelDifference set NumberOfComponentsPerPixel to " << this->NumberOfComponentsPerPixel << std::endl;
  }
  
  FullPixelDifference(const unsigned int numberOfComponents)
  {
    this->NumberOfComponentsPerPixel = numberOfComponents;
    //std::cout << "FullPixelDifference set NumberOfComponentsPerPixel to " << this->NumberOfComponentsPerPixel << std::endl;
  }
  
  float Difference(const typename FloatVectorImageType::PixelType &a, const typename FloatVectorImageType::PixelType &b)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < this->NumberOfComponentsPerPixel; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference;
  }
  
  static float Difference(const typename FloatVectorImageType::PixelType &a, const typename FloatVectorImageType::PixelType &b, unsigned int numberOfComponents)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < numberOfComponents; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference;
  }
  
  unsigned int NumberOfComponentsPerPixel;
};

struct FullSquaredPixelDifference
{
  FullSquaredPixelDifference(typename FloatVectorImageType::PixelType& examplePixel)
  {
    this->NumberOfComponentsPerPixel = examplePixel.GetNumberOfElements();
  }
  
  FullSquaredPixelDifference(const unsigned int numberOfComponents)
  {
    this->NumberOfComponentsPerPixel = numberOfComponents;
    //std::cout << "FullSquaredPixelDifference set NumberOfComponentsPerPixel to " << this->NumberOfComponentsPerPixel << std::endl;
  }
  
  float Difference(const typename FloatVectorImageType::PixelType &a, const typename FloatVectorImageType::PixelType &b)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < this->NumberOfComponentsPerPixel; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference*difference;
  }
  
  static float Difference(const typename FloatVectorImageType::PixelType &a, const typename FloatVectorImageType::PixelType &b, unsigned int numberOfComponents)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < numberOfComponents; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference*difference;
  }
  
  unsigned int NumberOfComponentsPerPixel;
};

struct ColorPixelDifference
{
  ColorPixelDifference(const unsigned int numberOfComponents)
  {
    if(numberOfComponents < 3)
      {
      std::cerr << "ColorPixelDifference can't call ColorPixelDifference on an image with " << numberOfComponents << " components!" << std::endl;
      exit(-1);
      }
  }
  
  static float Difference(const typename FloatVectorImageType::PixelType &a, const FloatVectorImageType::PixelType &b)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < 3; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference;
  }
  

};
 
struct DepthPixelDifference
{
  DepthPixelDifference(const unsigned int numberOfComponents)
  {
    if(numberOfComponents < 4)
      {
      std::cerr << "DepthPixelDifference can't call DepthPixelDifference on an image with " << numberOfComponents << " components!" << std::endl;
      exit(-1);
      }
  }
  
  static float Difference(const typename FloatVectorImageType::PixelType &a, const FloatVectorImageType::PixelType &b)
  {
    return fabs(a[3] - b[3]);
  }
};

#endif<commit_msg>Added a templated channel difference class.<commit_after>/*=========================================================================
 *
 *  Copyright <NAME> 2011 <EMAIL>
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#ifndef PIXELDIFFERENCE_H
#define PIXELDIFFERENCE_H

struct FullPixelDifference
{
  FullPixelDifference(typename FloatVectorImageType::PixelType& examplePixel)
  {
    this->NumberOfComponentsPerPixel = examplePixel.GetNumberOfElements();
    //std::cout << "FullPixelDifference set NumberOfComponentsPerPixel to " << this->NumberOfComponentsPerPixel << std::endl;
  }
  
  FullPixelDifference(const unsigned int numberOfComponents)
  {
    this->NumberOfComponentsPerPixel = numberOfComponents;
    //std::cout << "FullPixelDifference set NumberOfComponentsPerPixel to " << this->NumberOfComponentsPerPixel << std::endl;
  }
  
  float Difference(const typename FloatVectorImageType::PixelType &a, const typename FloatVectorImageType::PixelType &b)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < this->NumberOfComponentsPerPixel; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference;
  }
  
  static float Difference(const typename FloatVectorImageType::PixelType &a, const typename FloatVectorImageType::PixelType &b, unsigned int numberOfComponents)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < numberOfComponents; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference;
  }
  
  unsigned int NumberOfComponentsPerPixel;
};

struct FullSquaredPixelDifference
{
  FullSquaredPixelDifference(typename FloatVectorImageType::PixelType& examplePixel)
  {
    this->NumberOfComponentsPerPixel = examplePixel.GetNumberOfElements();
  }
  
  FullSquaredPixelDifference(const unsigned int numberOfComponents)
  {
    this->NumberOfComponentsPerPixel = numberOfComponents;
    //std::cout << "FullSquaredPixelDifference set NumberOfComponentsPerPixel to " << this->NumberOfComponentsPerPixel << std::endl;
  }
  
  float Difference(const typename FloatVectorImageType::PixelType &a, const typename FloatVectorImageType::PixelType &b)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < this->NumberOfComponentsPerPixel; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference*difference;
  }
  
  static float Difference(const typename FloatVectorImageType::PixelType &a, const typename FloatVectorImageType::PixelType &b, unsigned int numberOfComponents)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < numberOfComponents; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference*difference;
  }
  
  unsigned int NumberOfComponentsPerPixel;
};

struct ColorPixelDifference
{
  ColorPixelDifference(const unsigned int numberOfComponents)
  {
    if(numberOfComponents < 3)
      {
      std::cerr << "ColorPixelDifference can't call ColorPixelDifference on an image with " << numberOfComponents << " components!" << std::endl;
      exit(-1);
      }
  }
  
  static float Difference(const typename FloatVectorImageType::PixelType &a, const FloatVectorImageType::PixelType &b)
  {
    float difference = 0;

    float diff = 0;
    for(unsigned int i = 0; i < 3; ++i)
      {
      diff = fabs(a[i] - b[i]);
      difference += diff;
      }
    return difference;
  }
  

};

struct DepthPixelDifference
{
  DepthPixelDifference(const unsigned int numberOfComponents)
  {
    if(numberOfComponents < 4)
      {
      std::cerr << "DepthPixelDifference can't call DepthPixelDifference on an image with " << numberOfComponents << " components!" << std::endl;
      exit(-1);
      }
  }
  
  static float Difference(const typename FloatVectorImageType::PixelType &a, const FloatVectorImageType::PixelType &b)
  {
    return fabs(a[3] - b[3]);
  }
};

template <unsigned int Channel>
struct ChannelPixelDifference
{
  DepthPixelDifference(const unsigned int numberOfComponents)
  {
    if(numberOfComponents < Channel+1)
      {
      std::cerr << "ChannelPixelDifference can't compute difference in channel " << Channel << " of an image with only " << numberOfComponents << " components!" << std::endl;
      exit(-1);
      }
  }
  
  static float Difference(const typename FloatVectorImageType::PixelType &a, const FloatVectorImageType::PixelType &b)
  {
    return fabs(a[Channel] - b[Channel]);
  }
};

#endif
{'fraction_non_alphanumeric': 0.12812339331619538, 'fraction_numerical': 0.006375321336760925, 'mean_word_length': 3.7840629611411707, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7273560', 'n_tokens_mistral': 2862, 'n_tokens_neox': 2756, 'n_words': 741}