← back to roto on ba3a.dev

ConnectedComponents

Connected regions of a Mask. Foreground connects through all eight neighbours and background through the four edge neighbours — the usual pairing, so a diagonal chain of foreground pixels is one region and background never leaks through it.

Functions

Link copied to clipboard
fun fillHoles(mask: Mask): Mask

The mask with every hole filled: background the frame's border cannot reach becomes foreground.

Link copied to clipboard
fun largest(mask: Mask): Mask

Only the largest foreground region: the figure, without stray blobs elsewhere in the frame. Of regions equally large, the one reached first in row-major order wins.