# Create Gaussian Kernel¶

## Synopsis¶

Create a Gaussian kernel.

## Results¶

Output:

```Size: [3, 3]
Neighborhood:
Size:[3, 3]
DataBuffer:NeighborhoodAllocator { this = 0x7ffee598a9d8, begin = 0x7f7f502572a0, size=9 }
[-1, -1] 0
[0, -1] 0
[1, -1] 0
[-1, 0] 0.208375
[0, 0] 0.466801
[1, 0] 0.208375
[-1, 1] 0
[0, 1] 0
[1, 1] 0
```

## Code¶

### C++¶

```#include <itkGaussianOperator.h>

int
main(int, char *[])
{
using GaussianOperatorType = itk::GaussianOperator<float, 2>;
GaussianOperatorType gaussianOperator;
gaussianOperator.SetDirection(0); // Create the operator for the X axis derivative

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

std::cout << gaussianOperator << std::endl;

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

### Python¶

```#!/usr/bin/env python

import itk

gaussianOperator = itk.GaussianOperator[itk.F, 2]()
gaussianOperator.SetDirection(0)  # Create the operator for the X axis derivative

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

print(gaussianOperator)

for i in range(9):
print(str(gaussianOperator.GetOffset(i)) + " " + str(gaussianOperator.GetElement(i)))
```

## Classes demonstrated¶

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

A NeighborhoodOperator whose coefficients are a one dimensional, discrete Gaussian kernel.

GaussianOperator can be used to perform Gaussian blurring by taking its inner product with a Neighborhood (NeighborhoodIterator) that is swept across an image region. It is a directional operator. N successive applications oriented along each dimensional direction will effect separable, efficient, N-D Gaussian blurring of an image region.

GaussianOperator takes two parameters:

(1) The floating-point variance of the desired Gaussian function.

(2) The “maximum error” allowed in the discrete Gaussian function. “Maximum errror” is defined as the difference between the area under the discrete Gaussian curve and the area under the continuous Gaussian. Maximum error affects the Gaussian operator size. Care should be taken not to make this value too small relative to the variance lest the operator size become unreasonably large.

References: The Gaussian kernel contained in this operator was described by Tony Lindeberg (Discrete Scale-Space Theory and the Scale-Space Primal Sketch. Dissertation. Royal Institute of Technology, Stockholm, Sweden. May 1991.).

Note

GaussianOperator 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

NeighborhoodIterator

See

Neighborhood

ITK Sphinx Examples: