Hereby I would like explain the idea behind the patch I submitted last Saturday, ENH: Added ImageNeighborhoodPixelAccessPolicy for custom border extrapolation
I guess you have seen, last week, the ShapedImageNeighborhoodRange class for iteration over a neighborhood of pixels was merged onto the master branch of ITK. ShapedImageNeighborhoodRange has one specific way to deals with neighborhood pixel locations outside the image boundaries: it replicates the image border, just like itk::ZeroFluxNeumannBoundaryCondition. This border extrapolation method was implemented by its operator*() overload.
The new patch allows ITK users and developers to specify a different border extrapolation approach. It adds an extra template parameter, TImageNeighborhoodPixelAccessPolicy, to ShapedImageNeighborhoodRange, which specifies the “pixel access policy”: it specifies both the access to the pixel data and the border extrapolation method.
By default, BorderReplicatingImageNeighborhoodPixelAccessPolicy is used. But anyone can provide a custom policy class, as long as it has a GetPixelValue, a SetPixelValue, and a constructor, as follows:
template <typename TImage> class MyPolicy
{
using NeighborhoodAccessorFunctorType = typename TImage::NeighborhoodAccessorFunctorType;
using PixelType = typename TImage::PixelType;
using InternalPixelType = typename TImage::InternalPixelType;
using ImageDimensionType = typename TImage::ImageDimensionType;
static constexpr ImageDimensionType ImageDimension = TImage::ImageDimension;
public:
MyPolicy(
const Size<ImageDimension> & imageSize,
const OffsetType& offsetTable,
const NeighborhoodAccessorFunctorType& neighborhoodAccessor,
const IndexType& pixelIndex) ITK_NOEXCEPT
PixelType GetPixelValue(
const InternalPixelType* const imageBufferPointer) const ITK_NOEXCEPT;
void SetPixelValue(
InternalPixelType* const imageBufferPointer,
const PixelType& pixelValue) const ITK_NOEXCEPT;
};
Please have a look at how BorderReplicatingImageNeighborhoodPixelAccessPolicy was implemented: http://review.source.kitware.com/#/c/23366/4/Modules/Core/Common/include/itkBorderReplicatingImageNeighborhoodPixelAccessPolicy.h
In a similar way, other boundary conditions could also be implemented. With zero-cost runtime overhead, because the selection of the policy class is done at compile-time
Of course, I think it would be nice if this patch could still be included with ITK 5.0.0. But I can understand it it’s now too late in the game. It also depends on whether users would want to have this feature quickly. What do you think?
[Update, May 4, 2018: adapted text to Patch Set 4.]