I want the brown segmentation shrink a little, and the yellow segmentation grow a little, only on the edges of both segmentations. So I selected “inside all visible segments.” But nothing changes after clicking “Apply.” Even if I make the margin size very large, nothing changes. What should I change to fix the problem?
Try setting the editable region to “Inside critical structures” (the segment you want to shrink), and then select the segment you want to grow and grow it by your desired margin. I suspect that while your masking settings seem OK to me, there is either a bug or a complication in applying them, and this is an alternative approach that should achieve the same thing.
I agree that it should work like this. Especially as you say that you tried larger margins… The only thing I can think of is maybe the invisible segments are interfering somehow. If you delete them (just for the sake of debugging) and try the same thing does it work?
What Slicer version do you use? Is it possible for you to share this scene?
Thank you. I agree it could generally achieve the similar purpose, but I thought in theory the two approaches are different.
When selecting “Inside all visibal segments,” shrink of critical structures should only change the segmentation in-between it and dental material, but both segments as a whole will not shrink(so the edge between critical structure and box will not change).
When selecting “"Inside critical structures” only, the entire critical structure segments will shrink, and that will include the edge inbetween critical structure and box.
I want to change the pink edge into dental material. At first when I select Editable Area as “Inside critical structures,” I can’t paint anything. But when I select “everything,” you can see that the painter tool is working.
Even if I try to select “Inside visible segmentation” and only let dental material and critical structures as visible, I still cannot paint anything.
Save the scene into an MRB file (see in documentation if unsure) then share the file via the same drive you shared the video with.
I watched the video and I think the first painting attempt should work. Now the only thing that occurs to me is that the geometry of the segmentation and the underlying image might be different. If you use “inside critical structures” but with “Sphere brush” checked, does it make a difference?
slicer-skill says this after looking at this thread and the relevant code, might be worth a try:
Technical Analysis of the Margin + Masking Interaction
Looking at the source code, the Margin effect uses ModificationModeSet when applying results (SegmentEditorMarginEffect.py:213). Here’s why “inside all visible segments” masking effectively nullifies it:
The code path:
processMargin() (SegmentEditorMarginEffect.py:168-213) computes the grown/shrunk labelmap using vtkITKImageMargin, then calls:
self.scriptedEffect.modifySelectedSegmentByLabelmap(
modifierLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeSet)
ModifySegmentByLabelmap() (vtkSlicerSegmentEditorLogic.cxx:1663) applies masking. When mask mode is not “Everywhere” (line 1722), it:
GenerateEditMask() (vtkMRMLSegmentationNode.cxx:591-682) generates a binary mask that is 1 inside all visible segments and 0 outside
Applies this mask to the modifier labelmap (line 1821), zeroing out any voxels outside visible segments
The critical “Set” mode preservation (lines 1823-1847): Because ModificationModeSet replaces the entire segment, the code preserves the segment’s existing content outside the mask region — it adds back the original segment data wherever the mask blocked editing.
Why growing fails:
The expanded voxels from the Margin filter are, by definition, outside all existing visible segments. The mask zeros them out. Result: no change.
Why shrinking fails:
The Margin filter produces a smaller labelmap. But ModificationModeSet + masking preserves the original segment data outside the mask. The voxels that should be removed at segment edges get added back. Result: no change.
The paint issue (post #6):
@cpinter’s hypothesis about geometry misalignment is likely correct. If the segmentation’s labelmap grid doesn’t align with the source volume, the “Inside [segment]” mask can end up empty at the paint location. The “Sphere brush” test would confirm this because it samples in world coordinates rather than relying on exact voxel alignment.
Possible Fixes / Workarounds
For the user’s immediate goal (shift boundary between two segments):
Workaround: Use the Logical Operators effect — copy the brown segment, shrink it with masking set to “Everywhere,” then subtract the shrunken copy from brown
and add the difference to yellow.
Workaround: Set masking to “Everywhere” but use the Overwrite mode set to “Visible segments” — this way growing yellow will automatically eat into brown at
their shared boundary.
For the underlying bug: The Margin effect could potentially bypass masking for the computation itself and only use masking to constrain which boundaries are affected, rather than having the general masking pipeline mask the result. This would require changes to how the Margin effect interacts with the masking system.
And also: I remember in the past, I wanted to use scissor tool but only to cut in a limited depth. Since the scissors tool will cut with an infinite depth, so I was thinking of creating a volume mask and make it the editable area, so that scissors only cut things off within that masked volume.
I created the volume mask using “fill between slices”, but when I make it the editable area and used scissors tool, I found that scissors tool still cut to finite depth, which include voxels outside of the masked editable area.
Back then I was confused and didn’t proceed. Now I found that they are all about “editable area”, so maybe this description also helps with debug? I will add a video if I could reproduce the scene.
The Margin effect and any non-Everywhere masking mode are fundamentally incompatible due to how ModificationModeSet interacts with GenerateEditMask.
For anyone hitting this right now, here are two working workarounds depending on what you are trying to do:
If you just need the Margin tool to actually work: Set Editable area to “Everywhere” before hitting Apply. This bypasses the mask conflict entirely. The Margin computation runs clean.
If you need to shift a boundary between two specific segments (the original use case in this thread): Skip Margin entirely and use Python approach. I can write you the script you can dm me.