Obtaining Segmentations for Fiducials

I also have models of the segmentation but the model seems even more imperfect than the segmentation.

Is there a way to do this with the segmentation itself ?

The model that Segmentations module generates from the segment should not be worse. Maybe you can smooth the binary labelmap representation and disable smoothing for the surface generation to make the generated surface more closely match the labelmap. Can you attach an example image so that we have a better idea of the difficulty of the problem?

Here is an example. I think the model boundaries aren’t really close enough to the segmentation itself.
Also in some cases, two neighboring models cross each other , i.e. one single point seems to belong to two different models at the same time.

This segmentation looks good. There is no significant noise or other issues.

You can reduce or disable surface smoothing to make the generated surface match the labelmap more closely.

I don’t know how to disable surface smoothing to generate the model, could you help me with that ?

See Segment editor documentation page (look for “smoothing”).

Thank you for all the information !
I found the smoothing settings.

But when I try to view new models I cannot see them, even though the visibilty box is checked. What might cause that ?

And I also obtained the minimum distances. But some of the distances are negative. Should I take their absolute value ?

Thanks !

Computaiton of closed surface representation takes time, so it is not created unless it is requested.
You can create it in Segmentations module by clicking “Create” button in the corresponding row in Representations section (or in Segment Editor module click “Show 3D”).

Negative distance means inside, positive distance means outside.

Hi again,
I have a few questions about this :
See this example in the script repository:

When I run this script, I got the error:

AttributeError: ‘NoneType’ object has no attribute ‘AddObserver’

(In line: markupsFiducialNode.AddObserver(slicer.vtkMRMLMarkupsPlaneNode.PointModifiedEvent, printSegmentNames)
How can we solve this error ?

  1. Assume that some of the segmentations are visible in the current segment, but are visible in different anterior/posterior positions. Can this script find those segments ? Ie., I need to do this in 3D coordinates, not just in one slice.

Thank you so much.

You need to place a markups fiducial point before you run the script.

I already have them, but I am still getting the same error.

Do you use latest Slicer Preview Release?

I am using Slicer 4.11. Should I switch to 4.10 ?

Latest Slicer-4.11 should work well.

This line sets the first markups fiducial node in the scene in variable markupsFiducialNode:

markupsFiducialNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLMarkupsFiducialNode")

If you get an error that markupsFiducialNode is None then it means that there is no markups fiducial node in your scene, so you need to add one. Can you post a screenshot of your Slicer application window?

I think I found the problem, by your help.
But I have another question : I have several different fiducial files. How can I modify

markupsFiducialNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLMarkupsFiducialNode")

to pick the one that I need to use ?


Complete this programming tutorial to learn about basics of Python scripting in Slicer: https://www.slicer.org/wiki/Documentation/Nightly/Training#PerkLab.27s_Slicer_bootcamp_training_materials

OK I also solved it.

So the last thing : I need to check the segments in all slices, not just in one. It seems like this script is missing the segments which are not visible in the current slice.
Is it possible to loop over all slices so that segments of different slices are also covered ?


If you show the binary labelmap representation in the slice view then you should be able to get all segments.

You can also use vtkMRMLSegmentationsDisplayableManager3D’s Pick3D method, and then get GetPickedNodeID and GetPickedSegmentID to get the picked node and segment, but these only return the first hit.

I have many segments and I don’t think I can make all of them visible in just one slice… Any suggestions about that ?

I couldn’t find an example for using vtkMRMLSegmentationsDisplayableManager3D. I am trying :
sliceViewWidget = slicer.app.layoutManager().sliceWidget(sliceViewLabel)
segmentationsDisplayableManager = sliceViewWidget.sliceView().displayableManagerByClassName(‘vtkMRMLSegmentationsDisplayableManager3D’)

But segmentationsDisplayableManager is returned as None.

Individual segments don’t have to be visible in that slice view, just the segmentation overall. Again, it is important to set the visible representation to binary labelmap.

If you want to try 3D displayable manager then retrieve that from a 3D view.