Create A Backward Difference Operator

Synopsis

Create a backward difference operator

Results

Output:

Size: [3, 3]
Neighborhood:
    Radius:[1, 1]
    Size:[3, 3]
    DataBuffer:NeighborhoodAllocator { this = 0x7fffb3cae9f8, begin = 0x1dd0e50, size=9 }

[-1, -1] 0
[0, -1] 0
[1, -1] 0
[-1, 0] -1
[0, 0] 1
[1, 0] 0
[-1, 1] 0
[0, 1] 0
[1, 1] 0

Code

C++

#include <itkBackwardDifferenceOperator.h>

int
main(int, char *[])
{
  using PixelType = float;
  constexpr unsigned int Dimension = 2;

  using BackwardDifferenceOperatorType = itk::BackwardDifferenceOperator<PixelType, Dimension>;
  BackwardDifferenceOperatorType backwardDifferenceOperator;

  // Create the operator for the X axis derivative
  backwardDifferenceOperator.SetDirection(0);

  itk::Size<Dimension> radius;
  radius.Fill(1);

  backwardDifferenceOperator.CreateToRadius(radius);

  std::cout << "Size: " << backwardDifferenceOperator.GetSize() << std::endl;

  std::cout << backwardDifferenceOperator << std::endl;

  for (unsigned int i = 0; i < 9; i++)
  {
    std::cout << backwardDifferenceOperator.GetOffset(i) << " " << backwardDifferenceOperator.GetElement(i)
              << std::endl;
  }
  return EXIT_SUCCESS;
}

Classes demonstrated

template<typename TPixel, unsigned int TDimension = 2, typename TAllocator = NeighborhoodAllocator<TPixel>>
class BackwardDifferenceOperator : public itk::NeighborhoodOperator<TPixel, TDimension, TAllocator>

Operator whose inner product with a neighborhood returns a “half” derivative at the center of the neighborhood.

BackwardDifferenceOperator uses backward differences i.e. F(x) - F(x-1) to calculate a “half” derivative useful, among other things, in solving differential equations. It is a directional NeighborhoodOperator that should be applied to a Neighborhood using the inner product.

Note

BackwardDifferenceOperator does not have any user-declared “special member function”, following the C++ Rule of Zero: the compiler will generate them if necessary.

ITK Sphinx Examples:

See itk::BackwardDifferenceOperator for additional documentation.