erode3x3#

rlemasklib.RLEMask.erode3x3(connectivity=4, inplace=False)[source]#

Erode a mask with a 3x3 kernel.

After erosion, only those pixels remain foreground that were foreground before and all its neighbors (according to the specified connectivity, 4-way or 8-way) are also foreground.

The kernel shape depends on connectivity:

connectivity=4: connectivity=8:

At the image border, pixels are treated as if the mask was extended by replicating the edge values. This means foreground pixels touching the border can survive erosion.

Parameters:
  • connectivity (int) – either 4 or 8, the connectivity of the erosion. 4 means a cross-shaped kernel, 8 means a square kernel.

  • inplace (bool) – whether to perform the operation in place or to return a new object

Returns:

The RLEMask object representing the eroded mask (self if inplace=True)

Return type:

RLEMask

Examples

With connectivity=4 (cross-shaped kernel), a pixel survives if all 4-connected neighbors are foreground:

.erode3x3(connectivity=4) ==

With connectivity=8 (square kernel), a pixel survives only if all 8 neighbors are foreground. The protrusion causes more erosion:

.erode3x3(connectivity=8) ==

Border pixels are preserved when their neighbors (including replicated border) are all foreground:

.erode3x3(connectivity=4) ==

See also

erode() for arbitrary kernel shapes. erode5x5() for a 5x5 kernel.