Create Derivative Kernel#
Synopsis#
Create a derivative kernel.
Results#
Output:
Size: [3, 3]
Neighborhood:
Radius:[1, 1]
Size:[3, 3]
DataBuffer:NeighborhoodAllocator { this = 0x7ffeec8f19e8, begin = 0x7f822c2a8f00, size=9 }
[-1, -1] 0
[0, -1] 0
[1, -1] 0
[-1, 0] 0.5
[0, 0] 0
[1, 0] -0.5
[-1, 1] 0
[0, 1] 0
[1, 1] 0
Code#
Python#
#!/usr/bin/env python
import itk
derivativeOperator = itk.DerivativeOperator[itk.F, 2]()
derivativeOperator.SetDirection(0) # Create the operator for the X axis derivative
radius = itk.Size[2]()
radius.Fill(1)
derivativeOperator.CreateToRadius(radius)
print("Size: " + str(derivativeOperator.GetSize()))
print(derivativeOperator)
for i in range(9):
print(
str(derivativeOperator.GetOffset(i))
+ " "
+ str(derivativeOperator.GetElement(i))
)
C++#
#include <itkDerivativeOperator.h>
int
main()
{
using DerivativeOperatorType = itk::DerivativeOperator<float, 2>;
DerivativeOperatorType derivativeOperator;
derivativeOperator.SetDirection(0); // Create the operator for the X axis derivative
itk::Size<2> radius;
radius.Fill(1);
derivativeOperator.CreateToRadius(radius);
std::cout << "Size: " << derivativeOperator.GetSize() << std::endl;
std::cout << derivativeOperator << std::endl;
for (unsigned int i = 0; i < 9; ++i)
{
std::cout << derivativeOperator.GetOffset(i) << " " << derivativeOperator.GetElement(i) << std::endl;
}
return EXIT_SUCCESS;
}
Classes demonstrated#
-
template<typename TPixel, unsigned int VDimension = 2, typename TAllocator = NeighborhoodAllocator<TPixel>>
class DerivativeOperator : public itk::NeighborhoodOperator<TPixel, VDimension, TAllocator> A NeighborhoodOperator for taking an n-th order derivative at a pixel.
DerivativeOperator’s coefficients are a tightest-fitting convolution kernel for calculating the n-th order directional derivative at a pixel. DerivativeOperator is a directional NeighborhoodOperator that should be applied to a Neighborhood or NeighborhoodPointer using the inner product method.
An example operator to compute X derivatives of a 2D image can be created with:
and creates a kernel that looks like:using DerivativeOperatorType = itk::DerivativeOperator<float, 2>; DerivativeOperatorType derivativeOperator; derivativeOperator.SetDirection(0); // X dimension itk::Size<2> radius; radius.Fill(1); // A radius of 1 in both dimensions is a 3x3 operator derivativeOperator.CreateToRadius(radius);
0 0 0 0.5 0 -0.5 0 0 0
- Note
DerivativeOperator does not have any user-declared “special member function”, following the C++ Rule of Zero: the compiler will generate them if necessary.
- See
NeighborhoodOperator
- See
Neighborhood
- See
ForwardDifferenceOperator
- See
BackwardDifferenceOperator
- ITK Sphinx Examples: