Skip to content

feat(fill_holes_v2): true multi-label fill holes#10

Merged
william-silversmith merged 55 commits intomainfrom
wms_multilabel_fill
Oct 21, 2025
Merged

feat(fill_holes_v2): true multi-label fill holes#10
william-silversmith merged 55 commits intomainfrom
wms_multilabel_fill

Conversation

@william-silversmith
Copy link
Copy Markdown
Contributor

@william-silversmith william-silversmith commented Oct 15, 2025

A new implementation of fill_holes that finally treats fill_holes as a multi-label problem, accelerating hole filling one to two orders of magnitude. The problem this is attempting to solve is performing hole filling on an 813^3 u64 image could take multiple hours (doing it on a 513^2 image could take minutes to ~20 minutes). This new implementation can perform hole filling in seconds to about a minute.

One difference is that this implementation always returns an array of filled and holes whereas the original version would return filled and possible a fill count and a set of hole labels in the interests of memory efficiency. However, with the advent of crackle compressed arrays, concerns about memory usage can be dispensed with.

filled_labels, hole_labels = fastmorph.fill_holes_v2(labels, return_crackle=True)

filled_labels, holes = fastmorph.fill_holes_v1(labels, remove_enclosed=True, return_removed=True)

v2 also supports fix_borders like v1. Where v1 has morphological_closing which applies a dilation then an erosion after hole filling, which can change the contours of labels, v2 has a merge_threshold between 0.0 to 1.0. The merge_threshold is the necessary ratio of the contact surface of a label over all contact surfaces to assign a parent label. 1.0 = only one parent is acceptable (same as standard hole filling). As merge_threshold decreases from 1, holes that poke just through the surface (e.g. an organelle that brushes against the plasma membrane) can be merged into the parent label. This strategy has the advantage of not altering the shape of the base labels as well as being faster.

The fill_holes_v2 interface is different, so to preserve backwards compatibility, we'll keep both for now with fill_holes and fill_holes_v1 aliases of each other.

@william-silversmith william-silversmith self-assigned this Oct 15, 2025
@william-silversmith william-silversmith added the enhancement New feature or request label Oct 15, 2025
@william-silversmith william-silversmith merged commit 7e919b9 into main Oct 21, 2025
15 checks passed
@william-silversmith william-silversmith deleted the wms_multilabel_fill branch October 21, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant