merge_tile_labels
blockbuster.merge_tile_labels(labeled: Union['da.Array', str, Path], write_to: Union[str, Path, None] = None, *, input_component: str = 'labels', output_component: str = 'labels', overlap: int = 0, sequential_labels: bool = False, n_workers: int | None = None, stage_dir: Union[str, Path, None] = None, keep_stage: bool = False, progress: bool = False) -> 'da.Array'
Merge per-tile labels into a globally consistent label array.
Standalone merge step — use this when you already have per-tile labels (from your own segmentation pipeline) and just need the boundary stitching.
Accepts either:
- A dask array of per-tile integer labels (e.g. output of
dask.array.map_blockson your own segmentation function). - A zarr store path whose
input_componentarray already contains per-tile labels written by your own pipeline.
Labels that touch across tile boundaries are merged into a single ID. The merge is zarr-native (boundary scan → scipy connected components → parallel relabel) — no dask task graph, scales to thousands of tiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labeled
|
Union['da.Array', str, Path]
|
Per-tile label array. Either a dask array or a path to a zarr store
that contains per-tile labels in |
required |
write_to
|
Union[str, Path, None]
|
Output zarr store path. When None, an auto-temp store is used. |
None
|
input_component
|
str
|
Array name inside a zarr input store (ignored for dask arrays). |
'labels'
|
output_component
|
str
|
Array name inside |
'labels'
|
overlap
|
int
|
If |
0
|
sequential_labels
|
bool
|
Renumber the merged labels to a contiguous |
False
|
n_workers
|
int | None
|
Parallel workers for the relabel step. Default |
None
|
stage_dir
|
Union[str, Path, None]
|
Directory for the temp stage zarr when labeled is a dask array. Default: a system temp directory. |
None
|
keep_stage
|
bool
|
Keep the temp stage zarr after merging. Default False. |
False
|
progress
|
bool
|
Show a progress bar during the relabel step. |
False
|
Returns:
| Type | Description |
|---|---|
Array
|
Merged label array (int32) backed by |
Examples:
From a dask array of per-tile labels:
>>> import dask.array as da
>>> from blockbuster import merge_tile_labels
>>>
>>> # your own tiling + segmentation
>>> image = da.from_zarr("image.zarr").rechunk((1, 1024, 1024))
>>> labeled = image.map_blocks(my_segment_fn, dtype="int32",
... meta=np.empty((0,) * image.ndim, dtype="int32"))
>>>
>>> merged = merge_tile_labels(labeled, write_to="labels.zarr", progress=True)
From a pre-staged zarr store (your pipeline already wrote labels):
>>> merged = merge_tile_labels(
... "my_staged_labels.zarr",
... input_component="raw_labels",
... write_to="merged_labels.zarr",
... sequential_labels=True,
... )
Trim overlap halos before merging:
>>> # if labeled was computed with da.overlap.overlap(depth=20)
>>> merged = merge_tile_labels(labeled, write_to="labels.zarr", overlap=20)
Source code in src/blockbuster/_merge.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |