Demonstrate All Operators#

Note

Wish List Still needs additional work to finish proper creation of example.

Synopsis#

Demonstrate all operators.

Results#

Note

Help Wanted Implementation of Results for sphinx examples containing this message. Reconfiguration of CMakeList.txt may be necessary. Write An Example <https://itk.org/ITKExamples/Documentation/Contribute/WriteANewExample.html>

Code#

C++#

#include <itkNeighborhoodOperator.h>

#include <itkDerivativeOperator.h>
#include <itkForwardDifferenceOperator.h>
#include <itkGaussianDerivativeOperator.h>
#include <itkGaussianOperator.h>
#include <itkImageKernelOperator.h>
#include <itkLaplacianOperator.h>
#include <itkSobelOperator.h>
#include <itkAnnulusOperator.h>
#include <itkBackwardDifferenceOperator.h>

#include <vector>

int
main()
{
  using DerivativeOperatorType = itk::DerivativeOperator<float, 2>;
  using ForwardDifferenceOperatorType = itk::ForwardDifferenceOperator<float, 2>;
  using GaussianDerivativeOperatorType = itk::GaussianDerivativeOperator<float, 2>;
  using GaussianOperatorType = itk::GaussianOperator<float, 2>;
  using ImageKernelOperatorType = itk::ImageKernelOperator<float, 2>;
  using LaplacianOperatorType = itk::LaplacianOperator<float, 2>;
  using SobelOperatorType = itk::SobelOperator<float, 2>;
  using AnnulusOperatorType = itk::AnnulusOperator<float, 2>;
  using BackwardDifferenceOperatorType = itk::BackwardDifferenceOperator<float, 2>;

  std::vector<itk::NeighborhoodOperator<float, 2> *> operators;
  operators.push_back(new DerivativeOperatorType);
  operators.push_back(new ForwardDifferenceOperatorType);
  operators.push_back(new GaussianDerivativeOperatorType);
  operators.push_back(new GaussianOperatorType);
  operators.push_back(new ImageKernelOperatorType);
  operators.push_back(new LaplacianOperatorType);
  operators.push_back(new SobelOperatorType);
  operators.push_back(new AnnulusOperatorType);
  operators.push_back(new BackwardDifferenceOperatorType);

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

  for (auto & operatorId : operators)
  {
    operatorId->SetDirection(0); // Create the operator for the X axis derivative
    operatorId->CreateToRadius(radius);
    // std::cout << *(operators[operatorId]) << std::endl;
    // operators[operatorId]->Print(std::cout);
    // std::cout << operators[operatorId]->GetNameOfClass() << std::endl;

    for (auto i = -operatorId->GetSize()[0] / 2; i <= operatorId->GetSize()[0] / 2; ++i)
    {
      for (auto j = -operatorId->GetSize()[1] / 2; j <= operatorId->GetSize()[1] / 2; ++j)
      {
        itk::Offset<2> offset;
        offset[0] = i;
        offset[1] = j;

        unsigned int neighborhoodIndex = operatorId->GetNeighborhoodIndex(offset);
        std::cout << operatorId->GetElement(neighborhoodIndex) << " ";
      }
      std::cout << std::endl;
    }
  }
  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TPixel, unsigned int VDimension, typename TAllocator = NeighborhoodAllocator<TPixel>>
class NeighborhoodOperator : public itk::Neighborhood<TPixel, VDimension, TAllocator>

Virtual class that defines a common interface to all neighborhood operator subtypes.

A NeighborhoodOperator is a set of pixel values that can be applied to a Neighborhood to perform a user-defined operation (i.e. convolution kernel, morphological structuring element). A NeighborhoodOperator is itself a specialized Neighborhood, with functionality to generate its coefficients according to user-defined parameters. Because the operator is a subclass of Neighborhood, it is a valid operand in any of the operations defined on the Neighborhood object (convolution, inner product, etc.).

NeighborhoodOperator is a pure virtual object that must be subclassed to be used. A user’s subclass must implement two methods:

(1) GenerateCoefficients the algorithm that computes the scalar coefficients of the operator.

(2) Fill the algorithm that places the scalar coefficients into the memory buffer of the operator (arranges them spatially in the neighborhood).

NeighborhoodOperator supports the concept of a “directional operator.” A directional operator is defined in this context to be an operator that is applied along a single dimension. Examples of this type of operator are directional derivatives and the individual, directional components of separable processes such as Gaussian smoothing.

How a NeighborhoodOperator is applied to data is up to the user who defines it. One possible use of an operator would be to take its inner product with a neighborhood of values to produce a scalar result. This process effects convolution when applied to successive neighborhoods across a region of interest in an image.

Note

NeighborhoodOperator 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:

Subclassed by itk::DerivativeOperator< TPixel, VDimension, TAllocator >, itk::ForwardDifferenceOperator< TPixel, VDimension, TAllocator >, itk::GaussianDerivativeOperator< TPixel, VDimension, TAllocator >, itk::GaussianOperator< TPixel, VDimension, TAllocator >, itk::ImageKernelOperator< TPixel, VDimension, TAllocator >, itk::LaplacianOperator< TPixel, VDimension, TAllocator >, itk::SobelOperator< TPixel, VDimension, TAllocator >

See itk::NeighborhoodOperator for additional documentation.