Create Laplacian Kernel#

Synopsis#

Create a Laplacian kernel.

Results#

Output:

Size: [3, 3]
Neighborhood:
Radius:[1, 1]
Size:[3, 3]
DataBuffer:NeighborhoodAllocator { this = 0x7ffee97e29e0, begin = 0x7f87798a8810, size=9 }
[-1, -1] 0
[0, -1] 1
[1, -1] 0
[-1, 0] 1
[0, 0] -4
[1, 0] 1
[-1, 1] 0
[0, 1] 1
[1, 1] 0

Code#

Python#

#!/usr/bin/env python

import itk

laplacianOperator = itk.LaplacianOperator[itk.F, 2]()
radius = itk.Size[2]()
radius.Fill(1)
laplacianOperator.CreateToRadius(radius)

print("Size: " + str(laplacianOperator.GetSize()))

print(laplacianOperator)

for i in range(laplacianOperator.GetSize()[0] * laplacianOperator.GetSize()[1]):
    print(
        str(laplacianOperator.GetOffset(i)) + " " + str(laplacianOperator.GetElement(i))
    )

C++#

#include <itkLaplacianOperator.h>

int
main()
{
  using LaplacianOperatorType = itk::LaplacianOperator<float, 2>;
  LaplacianOperatorType laplacianOperator;
  itk::Size<2>          radius;
  radius.Fill(1);
  laplacianOperator.CreateToRadius(radius);

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

  std::cout << laplacianOperator << std::endl;

  for (unsigned int i = 0; i < laplacianOperator.GetSize()[0] * laplacianOperator.GetSize()[1]; ++i)
  {
    std::cout << laplacianOperator.GetOffset(i) << " " << laplacianOperator.GetElement(i) << std::endl;
  }
  return EXIT_SUCCESS;
}

Classes demonstrated#

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

A NeighborhoodOperator for use in calculating the Laplacian at a pixel.

A NeighborhoodOperator for use in calculating the Laplacian at a pixel. The LaplacianOperator’s coefficients are a tightest-fitting convolution kernel.

For example, the simplest Laplacian Operator for 2D has the form:

0   1   0
1  -4   1
0   1   0

The LaplacianOperator is a non-directional NeighborhoodOperator that should be applied to a Neighborhood or NeighborhoodIterator using an inner product method (itkNeighborhoodInnerProduct). To initialize the operator, you need call CreateOperator() before using it.

By default the operator will be created for an isotropic image, but you can modify the operator to handle different pixel spacings by calling SetDerivativeScalings. The argument to SetDerivativeScalings is an array of doubles that is of length VDimension (the dimensionality of the image). Make sure to use 1/pixel_spacing to properly scale derivatives.

Note

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

See

NeighborhoodOperator

See

Neighborhood

ITK Sphinx Examples:

See itk::LaplacianOperator for additional documentation.