Skip to content

FunctorImageFilter doesn't propagate neighborhood radius

The problem

The function SetInputRequestedRegionsImpl() from otbFunctorImageFilter.hxx doesn't correctly propagate HasNeighborhood information to SetInputRequestedRegion().

As a consequence, neighborhood-aware filters built with otb::FunctorImageFilter will always return bogus lines on the streaming tiles borders.

Technical reason

Given,

template <typename HasNeighborhood, class Tuple, size_t... Is>
auto SetInputRequestedRegionsImpl(Tuple& t, const itk::ImageRegion<2>& region, std::index_sequence<Is...>, const itk::Size<2>& radius)
{
  return std::make_tuple(SetInputRequestedRegion(
       std::get<Is>(t), 
       region,
       radius,
       typename std::tuple_element<Is, HasNeighborhood>::type::value_type()  // <--- the issue
   )...);
}

whatever::value_type() will always zero-construct a boolean.

As a consequence, the pad parameter will always be false, and the requested input region will never take the neighborhood radius into account.

Solution

The typical fix will be:

template <typename HasNeighborhood, class Tuple, size_t... Is>
auto SetInputRequestedRegionsImpl(Tuple& t, const itk::ImageRegion<2>& region, std::index_sequence<Is...>, const itk::Size<2>& radius)
{
  return std::make_tuple(
          SetInputRequestedRegion(
                  std::get<Is>(t),
                  region,
                  radius,
                  std::tuple_element<Is, HasNeighborhood>::type::value  // <--- the fix!
                  )...
          );
}