Relabelling
patchworks.relabel_sequential_array(labels: np.ndarray) -> np.ndarray
Remap labels to a contiguous 0, 1, … N range.
Background (0) stays 0. Runs in one np.unique + a lookup-table gather,
i.e. O(voxels) — unlike dask's relabel_sequential which is O(n_chunks²).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
ndarray
|
Integer label array (may have gappy ids). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Labels remapped to a contiguous |
Examples:
Source code in src/patchworks/_relabel.py
patchworks.relabel_sequential_zarr(store_path: str, component: str = 'labels') -> int
Relabel a written label zarr to contiguous ids, in place. Returns N.
Two-pass streaming algorithm — safe for arrays far larger than RAM. Pass 1 collects unique ids (bounded memory: a set). Pass 2 applies the lookup-table remap chunk by chunk.