Kernel Operation Filter

Applies a 2D kernel to an input image.

Category

category_image_operation Image Processing

Node

kernel2d_node

Parameters

KernelType: what kind of kernel to use (see below for a full description)

KernelSize: for specific kernels the size can be specified (used in both x and y directions)

StandardDeviation: for specific kernels this may be used as a parameter for the function

StructuringElement: for specific kernels this indicates what shape is to be used when applying them

Inputs

Input: the input to apply the kernel to

Outputs

Output: the output of the kernel operation

Effect of the Filter

This filter applies a 2D kernel to the input image. This is useful for blurring the image, making edges more visible, etc.

Continuous Data vs. Mask

The 2D kernel filter may be applied to either continuous data (such as e.g. a grayscale image), or a mask. Only the Dilation and Erosion kernel types may be applied to a mask. All kernel types can be applied to continuous data.

When the input image contains multiple channels (such as a spectrum for each pixel), the kernel will be applied to each channel independently.

Fixed Kernels (GradientModulus, Laplace)

There are two fixed kernels that are implemented. They have no further parameters.

The GradientModulus kernel will calculate the modulus of the gradient at that specific point. For points that are not at the boundary this will be the symmetrical numerical derivative in both x and y direction:

|\nabla I|(x,y) = \sqrt{\left(\frac{I(x+1, y) - I(x-1, y)}{2}\right)^2 + \left(\frac{I(x, y+1) - I(x, y-1)}{2}\right)^2}

For points that are at the boundary the respective derivatives will not be symmetrical (e.g. I(1, y) - I(0, y) for the x derivative at the left boundary).

The Laplace kernel will apply the discrete laplace operator to each point in the image. The Laplace kernel is given by the following fixed matrix:

0

1

0

1

-4

1

0

1

0

At the boundary the Laplace kernel will be treated the same way a function kernel (see next section) is treated (albeit with a fixed normalization factor of 1).

Function Kernels (Gaussian, LoG, Box Blur)

A function kernel allows the user to specify a kernel size (which will result in the kernel consisting of the function being evaluated in a square matrix of that size), and for some functions also a width parameter (called StandardDeviation, in the following the mathematical symbol \sigma will be used).

The kernel size has to be odd, and for the purpose of the following mathematical expressions the middle row and columns are considered to be the origin.

The Gauss kernel is a 2D Gaussian function given by the expression:

K(x, y) = \mathrm{exp}\left( - \frac{x^2 + y^2}{2 \sigma^2} \right)

The LoG kernel (Laplace of Gaussian) is given by the following function:

K(x, y) = - \frac{1 - \frac{x^2 - y^2}{2\sigma^2}}{\pi\sigma^4} \mathrm{exp}\left( - \frac{x^2 + y^2}{2 \sigma^2} \right)

The Box Blur kernel is a kernel with a constant value of 1 for all entries of the matrix, i.e.

K(x, y) = 1

(This will function like a 2D generalization of a moving average.)

All kernels will be normalized by the sum of all of their elements when they are applied to the image.

At the boundaries of the image the input image will be mirrored along the first row or column (but so that the first row or column isn’t part of the mirrored image), so that any function kernel can also be applied at or close to the boundaries.

If a function kernel is applied to an image that is so small that the kernel would never fit, the filter will automatically choose a smaller kernel size (while keeping the StandardDeviation parameter the same) so that it can perform the calculations.

Morphological Kernels (Dilation, Erosion)

These types of kernels provide simple morphological manipulations of the input image. The Dilation type will expand objects in the image by replacing each pixel with the maximum pixel value within the kernel range. The Erosion type will contract objects in the image by replacing each pixel with the minimum pixel value within the kernel range.

In addition to the KernelSize that can be modified, there is also the StructuringElement parameter, which indicates which shape the kernel should have when looking at neighboring pixels. A simple Square kernel will be a square of the given size; a Disk will be a circle of that radius (only pixels that have a distance of at most exactly the radius will be considered part of the kernel); a Cross kernel will only include pixels along the x and y axis starting from the current point. The following images show the shapes of the kernels for 2D (in the 5x5 case):

Square

Cross

Disc

kernel2d_shape_square

kernel2d_shape_cross

kernel2d_shape_disc

Example Data

The following table shows the effect of the kernel filter at default parameters when applied to grayscale data:

Input

GradientModulus

Laplace

Gaussian

LoG

BoxBlur

Dilation

Erosion

kernel2d_input_grayscale

kernel2d_output_gradientmodulus

kernel2d_output_laplace

kernel2d_output_gaussian

kernel2d_output_log

kernel2d_output_boxblur

kernel2d_output_dilation

kernel2d_output_erosion

(The Dilation and Erosion appear to have the inverse effect as desribed, but this is because this example data has a highly reflective background (close to 1), while the objects themselves reflect less light, so the effect is opposite to the effect that one might naively expect from these kernels.)

When applied to mask data, the following table shows the output of the filter when using default parameters:

Input

Dilation

Erosion

kernel2d_input_mask

kernel2d_output_mask_dilation

kernel2d_output_mask_erosion

Sequenced Operations (Line Cameras)

The Kernel Operation filter also works with line cameras (or in the case of hyperspectral cameras, Push Brooms) that pass in data line by line. However, since the filter needs to look at lines that will only come after the current line, this is solved by introducing a delay. For exmaple, if the kernel size is 3, when the first line is being processed, this filter will output nothing. Once the second line is being processed, the filter is able to output the result for the first line (because it can now look at the second line). The output of the filter hence has a delay of 1 line.

The processing framework will automatically take care of delays when the filter is then connected to other filters. For example, if one constructs a graph with the following node sequence:

_images/kernel2d_delay_example.png

Then the framework will ensure that the coefficient-wise subtraction filter will see the data belonging to the same pixels while subtracting them. This means that filter will have a delay of 1 as well, as a consequence of the delay that was introduced by the Kernel Operation filter.

Hence the user need not keep track of the delay themselves, as the processing framework will take care of that. However, if the user wants to perform inline processing with fluxEngine, they must be able to handle the fact that such a delay can be introduced. (The delay of any output can be queried in fluxEngine.)

The size of the delay is given by half the kernel size, rounded down. For example, a kernel of size 7 will introduce a delay of \lfloor 7/2 \rfloor = 3. The implicit size of the GradientModulus kernel is 3 (hence a delay of 1 in that case).