The erode algorithm performs a two dimensional (2D) filter operation on the input image with the provided 2D boolean kernel. The boolean kernel defines the pixel neighborhood for the filtering operation. The filter is a morphological operation called erode that is applied to each pixel of the input image masked by the boolean filter. The erode filter is equivalent to the minimum operation. The erode operation in binary images reduces or shrinks the foreground regions (in this case white in the figure below). This causes the undesirable small or thin objects to disappear.
\(K\) is the neighborhood kernel, where \(K \in \{0 \vee 1\}\).
\(k_w, k_h\) are the kernel's width and height, respectively.
\(min\) is the morphological filter operation.
The input may be binary, for the most-common binary morphology, or gray-scale, for the gray morphology. The other morphological filter is the Dilate, that is equivalent to the maximum operation. The dilate filter can be used after the erode filter to compose a morphological opening of an image.
C API functions
For list of limitations, constraints and backends that implements the algorithm, consult reference documentation of the following functions:
Define the kernel to be used. In this case, a simple 3x3 full neighborhood.
int8_t kernel[3 * 3] = { 1, 1, 1,
1, 1, 1,
1, 1, 1 };
Submit the algorithm for the chosen morphological filter to the stream, passing the kernel and other parameters. In this case, the erode filter. It'll be executed by the CPU backend.