### Linear Spatial Image Filtering

The Generic Scene Node Composer provides the following two nodes to perform linear spatial filtering with custom filter kernels:- ImageProcessing.
Compute. Filter. Filter - ImageProcessing.
Compute. Filter. Separable

### ImageProcessing.Compute.Filter.Filter

Linear spatial filtering is a versatile method for image filtering and can achieve many effects, such as blurring, sharpening, embossing, outlining, etc. Mathematically, linear spatial filter can be described by a 2D convolution operation.

The output image $\mathrm{f}[x,y]$ at slot output has the same size as the input image $\mathrm{a}[x,y]$ at slot input. To evaluate the equation for the 2D convolution, all kernel values $\mathrm{k}[x,y]$ outside the provided image size are assumed to be zero. Furthermore, if the convolution requires input image pixel values outside of the provided image size, the x-/y-positions are clamped to the spatially closest one on the border of the image (clamp to border).

#### Example

In order to get a better understanding of the 2D convolution, the figure below visualize the 2D convolution for a simple example, in which an input image $\mathrm{a}[x,y]$ of size 4 x 3 pixel is convolved with a kernel $\mathrm{k}[x,y]$ of size 3 x 3 pixel. If the kernel is assumed to be zero outside the provided spatial range and if the kernel's origin is located at its center pixel, the 2D convolution for this example simplifies to:

Thus, for a 3 x 3 kernel, for each output pixel $(x,y)$ we need to compute the weighted sum of the input image value at pixel position $(x,y)$ and the values of its 8 neighboring pixels (9 additions in total), whereby the multiplicative weights are given by the provided kernel (mirrored in x- and y-direction).

Identity (no filtering) | $\begin{bmatrix}0 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 0 \end{bmatrix} $ | |

Binomial blur filter | $\frac{1}{16}\begin{bmatrix}1 & 2 & 1\\ 2 & 4 & 2\\ 1 & 2& 1 \end{bmatrix}$ | |

Sharpening | $\begin{bmatrix}-1 & -1 & -1\\ -1 & 9 & -1\\ -1 & -1& -1 \end{bmatrix}$ | |

Gradient X | $\begin{bmatrix}1 & 0 & -1\\ 2 & 0 & -2\\ 1 & 0& -1 \end{bmatrix}$ | |

Gradient Y | $\begin{bmatrix}1 & 2 & 1\\ 0 & 0 & 0\\ -1 & -2& -1 \end{bmatrix}$ | |

Emboss | $\begin{bmatrix}-2 & -1 & 0\\ -1 & 1 & 1\\ 0 & 1& 2 \end{bmatrix}$ |

The graph Filter3x3 demonstrates this examples.

### ImageProcessing.Compute.Filter.Separable

This nodes performs linear spatial filtering with custom filter kernels. In contrast to the filter node described above, this node does not execute a convolution with a 2D kernel. Instead two 1D kernels in x- and y-direction are applied. If a 2D filter $\mathrm{k}[x,y]$ is realizable by two 1D filters, it is called separable. Mathematically, this can be described as:

The example Separable demonstrates how to use this node.