Using script for creating 'intersection' from 'Logical operators' of Segment Editor

Hi,

I am using python scrip to access Intersection operation from Logical Operators. I might did the script wrong. Using Logical Operators manually, the intersection between the orbit and the plate is:

I used the script:

#Logic operator
segmentEditorWidget.setActiveEffectByName("Logical operators")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("Operation","INTERSECT")

boneSegID = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName('bone_no_fx')
plateSegID = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName('plate_copy')

segmentEditorNode.SetSelectedSegmentID(plateSegID)
effect.setParameter("ModifierSegmentID", boneSegID)
effect.self().onApply()

It showed this effect:

I used segmentEditorNode.SetSelectedSegmentID(plateSegID) to set up the plate segment to be modified by the bone. I think I did this wrong. Can someone tell me how to properly set up the segment to be modified? This Segment editor — 3D Slicer documentation only shows setting up the modifier ID.

Here is a sample vol and segments and here is my snippet.

Your script works fine after commenting

# segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)

In the default Segment editor node, or if you show yours (segmentEditorWidget.show()), we can see that the geometry of ‘5 DummySeriesDesc!’ does not fit in the segmentation or output geometry.

1 Like

@chir.set Thank you for the response and solution! I cropped the volume to save the space but did not notify that I over cropped it.

As you suggested, my script did work after disable segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode).

However, when I tried to load the original volume of the masterVolumeNode set up, it stilled showed the same effect of not generating a proper intersection (here is the volume that fits the segmentation)

It also output this error message. It still shows there is a geometry mismatch between inputImage and imageToAppend

[VTK] Generic Warning: In vtkOrientedImageDataResample.cxx, line 1126
[VTK] vtkOrientedImageDataResample::MergeImage failed: geometry mismatch between inputImage and imageToAppend
[VTK] vtkSegmentationModifier::SetBinaryLabelmapToSegment: Invalid input labelmap
[Qt] virtual void qSlicerSegmentEditorAbstractEffect::modifySegmentByLabelmap(vtkMRMLSegmentationNode *, const char *, vtkOrientedImageData *, qSlicerSegmentEditorAbstractEffect::ModificationMode, const int *, bool) : Failed to add modifier labelmap to selected segment

Perhaps I simply should not set up a master volume for intersection? I wonder if it is due to the two segments were converted back from surface models. I also acquired these samples segmented by other people. The Segment Editor did work well though even with the original unfitted master volume.