Skip to content

Simplify overlay_segmentations using MergeLabelMap + LabelMapContourOverlay - #513

Merged
blowekamp merged 2 commits into
InsightSoftwareConsortium:mainfrom
blowekamp:overlay-segmentations-binary-projection
Sep 23, 2026
Merged

blowekamp merged 2 commits into
InsightSoftwareConsortium:mainfrom
blowekamp:overlay-segmentations-binary-projection

Conversation

@blowekamp

Copy link
Copy Markdown
Member

Summary

Simplifies overlay_segmentations in Python/05_Results_Visualization.ipynb.

Replaces the per-segmentation LabelMapContourOverlay calls plus manual mask
compositing (built on BinaryProjectionImageFilter/ToScalarImage) with a
single MergeLabelMapFilter + LabelMapContourOverlay call:

  • Each binary segmentation is cast directly to a label map (sitkLabelUInt8,
    all sharing label value 1).
  • MergeLabelMapFilter's default Keep method keeps each input's region
    distinct despite the shared label value, so contours for all segmentations
    (including overlapping ones) are drawn correctly in a single
    LabelMapContourOverlay call, instead of manually compositing per-segmentation
    results with a projection-based mask.

Verified with a standalone reproduction (two overlapping binary masks) that this
produces pixel-identical output to explicitly scaling each segmentation to a
unique label id before merging, and confirmed the notebook re-executes end-to-end
with jupyter nbconvert --execute with no errors.

@blowekamp
blowekamp force-pushed the overlay-segmentations-binary-projection branch 2 times, most recently from 043e87a to a44cce3 Compare September 21, 2026 20:43
@blowekamp
blowekamp marked this pull request as ready for review September 22, 2026 11:19
@blowekamp
blowekamp requested a review from zivy September 22, 2026 11:20
…verlay

Replace the per-segmentation LabelMapContourOverlay + manual mask
compositing (built on BinaryProjectionImageFilter/ToScalarImage) with a
single MergeLabelMapFilter + LabelMapContourOverlay call. Each binary
segmentation is cast to a label map (all label 1); MergeLabelMapFilter's
default KEEP method keeps each input's region distinct despite the shared
label value, so overlapping contours are handled correctly in one pass
instead of manual per-segmentation compositing.
@blowekamp
blowekamp force-pushed the overlay-segmentations-binary-projection branch from a44cce3 to 888bfe1 Compare September 22, 2026 12:44

@zivy zivy left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. I added missing words to the tests/additional_dictionary.txt, for the spellchecker.

@zivy
zivy force-pushed the overlay-segmentations-binary-projection branch from 5336840 to c0380b5 Compare September 23, 2026 03:59
@zivy
zivy force-pushed the overlay-segmentations-binary-projection branch from c0380b5 to e9e3478 Compare September 23, 2026 04:01
@blowekamp
blowekamp merged commit 66ab98a into InsightSoftwareConsortium:main Sep 23, 2026
8 checks passed
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