コード例 #1
0
  float operator()(const PixelType& a, const PixelType& b) const
  {
    using Helpers::length;
    using ITKHelpers::length;
    using Helpers::index;
    using ITKHelpers::index;
    assert(length(a) == length(b));

    float pixelDifference = 0.0f;
    for(unsigned int component = 0; component < N; ++component)
    {
      float componentDifference = fabs(index(a,component) - index(b,component));
      pixelDifference += componentDifference;
    }
    return pixelDifference;
  }
  float operator()(const PixelType& a, const PixelType& b) const
  {
    using Helpers::length;
    using ITKHelpers::length;
    using Helpers::index;
    using ITKHelpers::index;
    assert(length(a) == length(b));

    //assert(length(a) == Weights.size());
    if(length(a) != Weights.size())
    {
      std::stringstream ss;
      ss << "length(a) != Weights.size(). a is " << length(a) << " and weights is " << Weights.size();
      throw std::runtime_error(ss.str());
    }
    
    float pixelDifference = 0.0f;
    for(unsigned int component = 0; component < length(a); ++component)
      {
      float componentDifference = Weights[component] * fabs(index(a,component) - index(b,component));
      pixelDifference += componentDifference;
      }
    return pixelDifference;
  }