How set output volume from segmentation effects

I am trying to specify the output of the “Mask Volume” effect
how can I specify the input and output volumes ?
assuming I don’t want to use the master as input and I don’t know how to set the output?

e.g.

segmentEditorWidget.setActiveEffectByName('Mask volume')
maskEffect = segmentEditorWidget.activeEffect()
maskEffect.setParameter('FillValue', -1)
maskEffect.setParameter('Operation', 'FILL_OUTSIDE')

A good method for figuring out how to set code for items in the widget that you are using(SegmentEditorWidget in this case) is calling .children(), .findChildren(…) if you know the object type, or the more specific .findChild(…) if you know object type and object name.

From the slicer python interactive you can always do something like SegmentEditorWidget.[tab] to see what members are available to use.

1 Like

Have a look at the source code of this effect: https://github.com/lassoan/SlicerSegmentEditorExtraEffects/blob/master/SegmentEditorMaskVolume/SegmentEditorMaskVolumeLib/SegmentEditorEffect.py

It should be possible to set the input and output volume by modifying the segment editor node, but unfortunately this effect is not storing this information in MRML. This is a mistake, and this kind of mistakes are the reason why this effect is not yet integrated into Slicer core but still in this extension.

However, you can easily perform the Masking operation by calling maskVolumeWithSegment method of the effect.

@jamesobutler I have looked at those attributes but didn’t find a helpful clue. I see now how to use the .children()

@lassoan i looked through the source but can do some more investigation. how do I access maskVolumeWithSegment?

What would it take for the effect to be slicer core ready?

qMRMLSegmentEditorWidget::effectByName method should work.

See Move Mask Volume effect to Slicer core · Issue #10 · lassoan/SlicerSegmentEditorExtraEffects · GitHub

Basically it’s easier to just replicate the method maskVolumeWithSegment without the use of the widget as its pretty simply using vtkImageToImageStencil.

Yes, maskVolumeWithSegment method is all you need, so you can copy-paste as is into your script. The only disadvantage of cloning the code is that if there are any fixes or improvements then you don’t get those automatically, but since the amount of code is very small, most likely this won’t be an issue.