# 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:** 20\
**Page:** 1

<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 9, 2020, 6:59pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/1 "2020-09-09T18:59:08Z")

</div>

Operating system: Windows 10 Pro  
Slicer version: 4.10 and / or 4.11  
Hi all,

I have a set of fiducial points and a segmentation and I need to obtain the segments which the points belong to.  
There are so many points that I need an automated way to do that.  
How can I obtain the segments for each point using the Python interface ?  
I can see the regions manually by pointing the mouse on them, but I don’t know how I can get them by code.

Thank you all and best regards.

---

<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 9, 2020, 7:29pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/2 "2020-09-09T19:29:11Z")

</div>

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)

---

<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 11, 2020, 2:30am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/3 "2020-09-11T02:30:08Z")

</div>

Thanks !

Another related question : How can I obtain RAS coordinates of a segment ?  
I mean not just the extends or boundaries, but the whole segment.

Thank you and best regards.

---

<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 11, 2020, 2:37am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/4 "2020-09-11T02:37:31Z")

</div>

Sorry, I don’t understand what you mean. What would you like to do?

---

<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 11, 2020, 4:17am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/5 "2020-09-11T04:17:01Z")

</div>

I mean obtaining the RAS coordinates the segments in a segmentation.

I can get the max / min RAS coordinates, but I need the coordinates of the whole 3-D region, in RAS coordinates.

---

<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 11, 2020, 4:28am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/6 "2020-09-11T04:28:46Z")

</div>

“coordinates of the whole 3-D region” is undefined. A region’s boundaries have coordinates, the region’s center of gravity has coordinates, each non-zero voxel in the region has coordinates, etc. If you explain what you want to do with the data (maybe draw a sketch or annotate a screenshot) then it may make it more clear.

---

<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 11, 2020, 4:51am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/7 "2020-09-11T04:51:26Z")

</div>

Let me try to define what I need :

Let’s assume we have a region in a segmentation. That region covers a 3-D region in the MRI space.  
I need coordinates of the voxel in this 3-D, but not only in the MRI space, also in the RAS coordinates.

Or, if I can get the coordinates of all of the boundary points, that would also work well.

---

<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 11, 2020, 5:23am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/8 "2020-09-11T05:23:30Z")

</div>

You can get all segment voxels as numpy array (using `arrayFromVolume` method), get IJK coordinates of non-zero voxels using standard numpy array operations (`where`, …),and convert IJK to RAS as shown in examples in the script repository (see [here](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_markup_fiducial_RAS_coordinates_from_volume_voxel_coordinates)). You can also export segmentation to model and get coordinates of model points (see examples in script repository).

Although you can obtain all these data, this should be very rarely necessary. Are you sure you need coordinates of all these hundreds of thousands or millions of points? What is your overall goal?

---

<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 11, 2020, 6:50pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/9 "2020-09-11T18:50:57Z")

</div>

I agree but I need this for a complicated project where the segmentation itself is not perfect…  
I tried your suggestion but I have some problems - the resulting RAS coordinates are not correct yet.  
Also, I get this warning :

_arrayFromSegment is deprecated! Binary labelmap representation may be shared between multiple segments! Use arrayFromSegmentBinaryLabelmap to access a copy of the binary labelmap that will not modify the original labelmap. Use arrayFromSegmentInternalBinaryLabelmap to access a modifiable internal lablemap representation that may be shared between multiple segments._

I must be doing a mistake during IJK to RAS conversion, but I don’t know what it is.  
I am using Slicer 4.11. Should I do anything different for this version ? Or is the code provided in

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get\_markup\_fiducial\_RAS\_coordinates\_from\_volume\_voxel\_coordinates](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_markup_fiducial_RAS_coordinates_from_volume_voxel_coordinates)

fine for 4.11 ?

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 11, 2020, 7:09pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/10 "2020-09-11T19:09:48Z")

</div>

> [@FatihSogukpinar](#):
>
> arrayFromSegment is deprecated! Binary labelmap repr

This is just a deprecation warning. Since you don’t modify the segment, you can still use `arrayFromSegment`, but it would be more clear if you switched to `arrayFromSegmentBinaryLabelmap` function.

> [@FatihSogukpinar](#):
>
> this for a complicated project where the segmentation itself is not perfect

That’s fine - there is no such thing as a perfect segmentation. There are tools and best practices to manage that. If you tell what is your overall goal and what your problems are then we can give advice of what methods have been developed to address them.

---

<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 11, 2020, 7:38pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/11 "2020-09-11T19:38:21Z")

</div>

Let me summariza what my overall goal is :

I need to assign some fiducial points to their corresponding segments. But since the segmentation has errors, some points, though they are quite close to the segment, are not assigned to their regions.  
So I am trying to assign the points if they are close enough to a segment (say, 1mm away from the segment boundaries). This is why I need the RAS coordinates.  
But if there is a built-in function in Slicer which can do these kind of things, that would work, too.

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 11, 2020, 7:45pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/12 "2020-09-11T19:45:11Z")

</div>

There are many ways to achieve this, but one simple way is to export the segmentation to a model node then [get the closest point on the surface](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Measure_distance_of_points_from_surface).

---

<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 11, 2020, 7:53pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/13 "2020-09-11T19:53:36Z")

</div>

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 ?

---

<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 11, 2020, 8:02pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/14 "2020-09-11T20:02:15Z")

</div>

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?

---

<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 11, 2020, 8:16pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/15 "2020-09-11T20:16:19Z")

</div>

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.

 ![Screenshot_1](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/4/040096e2e23316333e6c84f57ccb1adcd3728fc1.jpeg)

---

<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 11, 2020, 8:18pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/16 "2020-09-11T20:18:49Z")

</div>

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.

---

<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 11, 2020, 8:27pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/17 "2020-09-11T20:27:15Z")

</div>

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

---

<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 11, 2020, 8:30pm UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/18 "2020-09-11T20:30:33Z")

</div>

> [@FatihSogukpinar](#):
>
> how to disable surface smoothing to generate the model

See [Segment editor documentation page](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmenteditor.html#panels-and-their-use) (look for “smoothing”).

---

<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 12, 2020, 3:29am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/19 "2020-09-12T03:29:25Z")

</div>

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 !

---

<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 12, 2020, 4:06am UTC](https://discourse.slicer.org/t/obtaining-segmentations-for-fiducials/13407/20 "2020-09-12T04:06:05Z")

</div>

> [@FatihSogukpinar](#):
>
> But when I try to view new models I cannot see them, even though the visibilty box is checked. What might cause that ?

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”).

> [@FatihSogukpinar](#):
>
> And I also obtained the minimum distances. But some of the distances are negative. Should I take their absolute value ?

Negative distance means inside, positive distance means outside.

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