Repository navigation
Fix mitochondria instances coating touching mitochondria - #189
Merged
Merged
Conversation
The heightmap was the normalized inverse distance to the boundaries, which is a plateau of equal height on the whole boundary band. The flooding order within one height level is unspecified, so a mitochondrion could flood along the boundary band of a touching one and "coat" it. Adding the boundary probability makes the band graded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sometimes a mitochondrion segmentation forms a thin shell around a neighbouring mitochondrion, along the neighbour's outer membrane. In some tomograms the shell even becomes a separate object of its own.
Cause
In
_run_segmentation, the watershed heightmap is the normalized inverse distance to the boundaries (boundaries >= boundary_threshold). That distance is 0 on the whole boundary band, so the band is a plateau where the heightmap is exactly 1.0. The order in which the seeded watershed floods voxels of the same height is unspecified. So once a seed's flood reaches a touching mitochondrion's band, it can spread along the outer layers of that band before the band's own mitochondrion claims them.Fix
Add the boundary probability to the heightmap so that the band is graded rather than flat. The barrier (
boundaries > threshold & foreground < threshold) is still set to the maximum of the heightmap. This is a two-line change.A tie-break by the distance to the nearest seed (as in
vesicles.py) was also tested on top of this. It made no measurable difference, so it is left out.Results
These are 6 tomograms, rerun from cached
mitochondria2predictions with the default parameters. Measurements are at the model resolution (2.87 nm).Instances that don't touch another one are unchanged or nearly so. Segmentations change where mitochondria touch.
Test
TestMitochondriaSegmentation.test_touching_mitochondriaintest/test_inference.pyruns on synthetic data and needs no network. It uses two balls with overlapping boundary bands. Without the fix, about 19k voxels of one ball (43%) go to the other; with the fix it is under 1%.test_inference.pypasses.🤖 Generated with Claude Code