# Segmentation algorithm used in 3D Slicer

**URL:** https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420
**Category:** Support
**Tags:** segmentation, dicom
**Created:** [July 4, 2019, 6:11pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420 "2019-07-04T18:11:49Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![sara04](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sara04](https://discourse.slicer.org/u/sara04)
#### Post date: [July 4, 2019, 6:11pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/1 "2019-07-04T18:11:49Z")

</div>

Hi,

I’m using 3D Slicer for tooth segmentation and I’ve created an stl model from ct scan (DICOM).  
I’ve done that using Segment editor module.

Can someone tell me which segmentation algorithm is used in slicer to create an stl model from ct scan?

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [July 4, 2019, 6:26pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/2 "2019-07-04T18:26:07Z")

</div>

> [@sara04](#):
>
> I’ve created an stl model from ct scan (DICOM)

> [@sara04](#):
>
> which segmentation algorithm is used in slicer to create an stl model from ct scan

I don’t understand the question. You said you did all that. Am I misunderstanding something?

---

<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: [July 4, 2019, 7:53pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/3 "2019-07-04T19:53:28Z")

</div>

If you mean which algorithms are used for generating closed surface from binary labelmap representation of the segmentation: see implementation [here](https://github.com/Slicer/Slicer/blob/master/Libs/vtkSegmentationCore/vtkBinaryLabelmapToClosedSurfaceConversionRule.cxx). In short: [vtkDiscreteFlyingEdges3D](https://vtk.org/doc/nightly/html/classvtkDiscreteFlyingEdges3D.html) followed by [vtkWindowedSincPolyDataFilter](https://vtk.org/doc/nightly/html/classvtkWindowedSincPolyDataFilter.html), [vtkDecimatePro](https://www.vtk.org/doc/nightly/html/classvtkDecimatePro.html) (optional), and [vtkPolyDataNormals](https://www.vtk.org/doc/nightly/html/classvtkPolyDataNormals.html).

---

<div class="post-metadata">

### Author: ![sara04](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sara04](https://discourse.slicer.org/u/sara04)
#### Post date: [July 5, 2019, 10:38am UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/4 "2019-07-05T10:38:53Z")

</div>

I need to write some theory about image segmentation and the things I’ve done in 3D Slicer. Since I used thresholding, I wanted to know the names of algorithms you used in implementation ( eg. k-means clustering).  
I’m a student and new to this so I don’t understand this very well. It will be very helpfull if you could give me the names of some algorithms you used. Hope you understand what I’m trying to say.

---

<div class="post-metadata">

### Author: ![sara04](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sara04](https://discourse.slicer.org/u/sara04)
#### Post date: [July 5, 2019, 10:40am UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/5 "2019-07-05T10:40:15Z")

</div>

Thank you @lassoan , I think you get my point. So, you used marching cubes algorithm and flying edges? I need to write something about this algorithms and I really want to write about algorithms that are implemented in slicer.

---

<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: [July 5, 2019, 12:19pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/6 "2019-07-05T12:19:50Z")

</div>

We did not use matching cubes. We used flying edges algorithm instead because it is faster. You can find description of the methods at the associated links.

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [July 5, 2019, 1:02pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/7 "2019-07-05T13:02:47Z")

</div>

I see, thanks! Andras gave you the details, but if you’re looking for some text, then I can send you my PhD thesis in which these are described in detail (it will be publicly accessible in a few weeks but I can send you an unofficial copy).

---

<div class="post-metadata">

### Author: ![sara04](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sara04](https://discourse.slicer.org/u/sara04)
#### Post date: [July 5, 2019, 5:49pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/8 "2019-07-05T17:49:03Z")

</div>

Thank you, that was really helpful!

---

<div class="post-metadata">

### Author: ![sara04](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sara04](https://discourse.slicer.org/u/sara04)
#### Post date: [August 30, 2019, 7:55pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/9 "2019-08-30T19:55:38Z")

</div>

@lassoan @cpinter  
Hi, I have another problem. I have done tooth segmentation and I extracted two stl files, tooth crown and root .  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/f/ef575454cd4154c07742f8f3f6ce499f8e9572be.png)

My question is… Is it possible to do an automatic segmentation of the contact surface between two volumes in contact (crown and root ) that were themselves constructed by segment editor? It is needed to impose the boundary conditions so as to treat two volumes as two bodies in contact.

---

<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: [August 30, 2019, 8:18pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/10 "2019-08-30T20:18:24Z")

</div>

You can export segments to models and then use “Model to model distance” extensions to compute distance between them. You can visualize the distance using color mapping or set a threshold value to show only parts that are closer to each other than the chosen threshold value (in Models module / Display / Scalars section).

---

<div class="post-metadata">

### Author: ![sara04](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sara04](https://discourse.slicer.org/u/sara04)
#### Post date: [August 31, 2019, 1:51pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/11 "2019-08-31T13:51:17Z")

</div>

I got this

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/2/c228cf672c13f58d619ba394d2ef73f0b7da9f87.png)

and then i set a threshold value to get this  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/e/1e15a1a241fe6025d62e9b76a9d63a3fcb4c245a.png)

Is it possible to save this last surface as stl file?  
I tried to save it but when I load it, i got the whole crown (first picture), not the surface I wanted.

---

<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 1, 2019, 2:50am UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/12 "2019-09-01T02:50:38Z")

</div>

Adjusting display options in Models module does not alter the model’s geometry, just modifies display settings. You can create a new model node from the displayed thresholded model by copy-pasting this line into the Python console:

```python
slicer.modules.models.logic().AddModel(getNode('sphere').GetDisplayNode().GetOutputMeshConnection())

```

If you just need a list of point IDs where the distance is smaller than a threshold (for example, 0.5) then you can get it by a few lines of Python code:

```python
import numpy as np
distances = slicer.util.arrayFromModelPointData(getNode('sphere'), 'Signed')
pointIDs = np.where(distances < 0.5)

```

(replace `sphere` by the actual name of the model node; and `Signed` by the actual name of the distance array)

---

<div class="post-metadata">

### Author: ![sara04](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sara04](https://discourse.slicer.org/u/sara04)
#### Post date: [September 1, 2019, 11:27am UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/13 "2019-09-01T11:27:47Z")

</div>

Thank you for your help. I created a new model and it’s fine now, but I can’t get a list of point IDs.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/0/e0bed5472d1e567dd1c7a8a9ff5eb40d6d0d31cc.png)

---

<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 1, 2019, 2:08pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/14 "2019-09-01T14:08:02Z")

</div>

There was a typo in the sample script above (distanceValues \<-\> distances), I’ve updated it now.

---

<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: [June 24, 2023, 2:12pm UTC](https://discourse.slicer.org/t/segmentation-algorithm-used-in-3d-slicer/7420/15 "2023-06-24T14:12:44Z")

</div>

A post was split to a new topic: [Segmentation and feature extraction of brain tumors](https://discourse.slicer.org/t/segmentation-and-feature-extraction-of-brain-tumors/30209)
