# Obtaining Segmentations for Fiducials

**URL:** https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407
**Category:** Support
**Created:** [September 9, 2020, 6:59pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407 "2020-09-09T18:59:08Z")
**Posts on this page:** 12
**Page:** 2

<div class="post-metadata">

### Author: ![FatihSogukpinar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fatihsogukpinar/32/7257_2.png) [@FatihSogukpinar](https://discourse.slicer.org/u/FatihSogukpinar)
#### Post date: [September 18, 2020, 8:26pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/21 "2020-09-18T20:26:14Z")

</div>

Hi again,  
I have a few questions about this :  
See this example in the script repository:  
[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get\_segments\_visible\_at\_a\_selected\_position](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_segments_visible_at_a_selected_position)

1. 

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.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 19, 2020, 3:01pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/22 "2020-09-19T15:01:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![FatihSogukpinar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fatihsogukpinar/32/7257_2.png) [@FatihSogukpinar](https://discourse.slicer.org/u/FatihSogukpinar)
#### Post date: [September 19, 2020, 8:56pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/23 "2020-09-19T20:56:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 19, 2020, 8:59pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/24 "2020-09-19T20:59:41Z")

</div>

Do you use latest Slicer Preview Release?

---

<div class="post-metadata">

### Author: ![FatihSogukpinar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fatihsogukpinar/32/7257_2.png) [@FatihSogukpinar](https://discourse.slicer.org/u/FatihSogukpinar)
#### Post date: [September 19, 2020, 9:01pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/25 "2020-09-19T21:01:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 19, 2020, 9:05pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/26 "2020-09-19T21:05:13Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![FatihSogukpinar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fatihsogukpinar/32/7257_2.png) [@FatihSogukpinar](https://discourse.slicer.org/u/FatihSogukpinar)
#### Post date: [September 19, 2020, 9:28pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/27 "2020-09-19T21:28:53Z")

</div>

> [@lassoan](#):
>
> t 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

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

```

to pick the one that I need to use ?

Thanks.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 19, 2020, 9:30pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/28 "2020-09-19T21:30:25Z")

</div>

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](https://www.slicer.org/wiki/Documentation/Nightly/Training#PerkLab.27s_Slicer_bootcamp_training_materials)

---

<div class="post-metadata">

### Author: ![FatihSogukpinar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fatihsogukpinar/32/7257_2.png) [@FatihSogukpinar](https://discourse.slicer.org/u/FatihSogukpinar)
#### Post date: [September 19, 2020, 9:59pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/29 "2020-09-19T21:59:13Z")

</div>

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 ?

Thanks.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 20, 2020, 2:01am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/30 "2020-09-20T02:01:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![FatihSogukpinar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fatihsogukpinar/32/7257_2.png) [@FatihSogukpinar](https://discourse.slicer.org/u/FatihSogukpinar)
#### Post date: [September 20, 2020, 6:35am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/31 "2020-09-20T06:35:41Z")

</div>

> [@lassoan](#):
>
> vtkMRMLSegmentationsDisplayableManager3D’s

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.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 20, 2020, 3:43pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/32 "2020-09-20T15:43:51Z")

</div>

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.

[Previous page](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407.md?page=1)
