Skip to content

remove_small_units builtin

remove_small_units(
    model,
    classes,
    *,
    min_volume=None,
    min_blocks=None,
    connectivity=6,
    domains=None,
    domain_column=None,
)

Reclassify connected units of block classes smaller than min_volume (or min_blocks blocks) into the class of their neighbors.

A unit joins blocks of one class whose parent cells share a face (connectivity=6) or a face, edge or corner (connectivity=26); sub-blocks of one parent cell touch. Units go smallest first, and each takes the class with the most volume among the blocks touching it, ties to the first class in sorted order, merging with the units of that class it touches. A unit left below the minimum has no neighbor to join: absent cells or other domains surround it. With domains (one label per block) or the domain_column of model, units and neighbors stay within a domain. Classes may be any labels, or the column of model holding them; the result has the same labels.

used in