Skip to content

added elf wrapper to cristae segment function #162

Merged
constantinpape merged 6 commits into
mainfrom
add-cristae-segment-wrapper
Mar 20, 2026
Merged

added elf wrapper to cristae segment function #162
constantinpape merged 6 commits into
mainfrom
add-cristae-segment-wrapper

Conversation

@lufre1
Copy link
Copy Markdown
Contributor

@lufre1 lufre1 commented Mar 18, 2026

and also masked the foreground prediction. Added binary erosion to mito_seg to avoid detecting cristae between mitochondria.

This resolves following issues:

  • cristae segmentation outside of mitochondria
  • cristae segmentation in between adjacent mitochondria
  • out-of-memory crashes for big volumes

…eground prediction. Added binary erosion to mito_seg to avoid detecting cristae between mitochondria
@lufre1 lufre1 requested a review from constantinpape March 18, 2026 10:18
@lufre1
Copy link
Copy Markdown
Contributor Author

lufre1 commented Mar 19, 2026

@constantinpape the changes we discussed are implemented now

Comment thread synapse_net/inference/cristae.py Outdated
mito_seg=None,
erode_voxels=3,
):
if mito_seg is not None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not be None given the current logic. I would avoid this check and directly apply the postprocessing.

Comment thread synapse_net/inference/cristae.py Outdated

# get the segmentation via seeded watershed
# Process instance erosion using global regionprops
if erode_voxels > 0:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would refactor this into a small function to improve the code readability.

Comment thread synapse_net/inference/cristae.py Outdated

# Load into memory to get accurate global bounding boxes and sizes.
# this can cause issue with limited memory (RAM)
mito_data = mito_seg[:] if hasattr(mito_seg, '__getitem__') else mito_seg
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case would we not have a __getitem__?

Comment thread synapse_net/inference/cristae.py Outdated
# Load into memory to get accurate global bounding boxes and sizes.
# this can cause issue with limited memory (RAM)
mito_data = mito_seg[:] if hasattr(mito_seg, '__getitem__') else mito_seg
eroded_mito_data = np.zeros_like(mito_data)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this in-place, i.e. directly write the output to mito_data. Then you avoid allocating the memory twice.

Comment thread synapse_net/inference/cristae.py
Comment thread synapse_net/inference/cristae.py Outdated
t0 = time.time()
ids, sizes = parallel.unique(seg, return_counts=True, block_shape=block_shape, verbose=verbose)
filter_ids = ids[sizes < min_size]
seg[np.isin(seg, filter_ids)] = 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.isin is very memory hungry. There is an implementation in elf.parallel you could use instead if you want to save memory.

Comment thread synapse_net/inference/cristae.py
@constantinpape constantinpape merged commit 0dd1097 into main Mar 20, 2026
3 checks passed
@constantinpape constantinpape deleted the add-cristae-segment-wrapper branch March 20, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants