# How to convert a vtkMRMLScalarVolumeNode to a vtkMRMLSegmentationNode

**URL:** <https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343>\
**Category:** Support\
**Tags:** segmentation, python, volume, binarylabelmap\
**Created:** [October 25, 2021, 5:31pm UTC](https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343 "2021-10-25T17:31:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkkkkkk123](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@kkkkkkk123](https://discourse.slicer.org/u/kkkkkkk123)\
**Post date:** [October 25, 2021, 5:31pm UTC](https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343/1 "2021-10-25T17:31:23Z")

</div>

Hi all,  
I’m trying to convert a vtkMRMLScalarVolumeNode to a new vtkMRMLSegmentationNode (in Python) and I don’t seem to get it figured out… The scalar volume is basically just a binary image but I want it to be rendered as a segmentation (contour) and not a volume.  
Does anyone know how I can achieve this? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [October 25, 2021, 6:50pm UTC](https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343/2 "2021-10-25T18:50:45Z")

</div>

You can programmatically use the segment editor tools to generate a segment from your binary image using a threshold (check out the segmentations section of the [script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#segmentations)), though there is probably a simpler way given that you basically already have a thresholded image. If it helps, it looks like you can load your volume as a segmentation (see instructions here [Segmentations — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmentations.html#import-an-existing-segmentation-from-volume-file)). That’s not exactly the same as converting an already loaded volume, but maybe it will work for you.

---

<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:** [October 26, 2021, 8:42am UTC](https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343/3 "2021-10-26T08:42:44Z")

</div>

There are convenience tools to do this conversion. Thresholding as suggested above is an error-prone workaround, so I suggest using the built-in function called `ImportLabelmapToSegmentationNode`, see [Slicer: vtkSlicerSegmentationsModuleLogic Class Reference](http://apidocs.slicer.org/master/classvtkSlicerSegmentationsModuleLogic.html#adf111c9bcd3ceb28d49028f6fc6a2506)

---

<div class="post-metadata">

**Author:** ![kkkkkkk123](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@kkkkkkk123](https://discourse.slicer.org/u/kkkkkkk123)\
**Post date:** [October 26, 2021, 8:48am UTC](https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343/4 "2021-10-26T08:48:13Z")

</div>

Thank you, it was indeed the preferred method! 😄

---

<div class="post-metadata">

**Author:** ![helenawill95](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/helenawill95/32/2650_2.png) [@helenawill95](https://discourse.slicer.org/u/helenawill95)\
**Post date:** [January 21, 2022, 12:32pm UTC](https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343/5 "2022-01-21T12:32:38Z")

</div>

I may have missed something, I see that the input to the function is a label map, is there anyway to input a volume Node instead i.e. convert the volume node to a segmentation then labelmap.

---

<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:** [January 21, 2022, 1:19pm UTC](https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343/6 "2022-01-21T13:19:09Z")

</div>

> [@helenawill95](#):
>
> convert the volume node to a segmentation then labelmap

When you say “convert the volume node to a segmentation” do you mean segmenting an anatomical image like a CT or MRI? For that you need to use the Segment Editor module.

---

<div class="post-metadata">

**Author:** ![helenawill95](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/helenawill95/32/2650_2.png) [@helenawill95](https://discourse.slicer.org/u/helenawill95)\
**Post date:** [January 21, 2022, 2:28pm UTC](https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343/7 "2022-01-21T14:28:43Z")

</div>

I have a binary 3D mask of a structure that I load as a volume node instead of a segmentation node, I then just want to convert it to a segmentation node later on in a post-processing step.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [January 21, 2022, 8:06pm UTC](https://discourse.slicer.org/t/how-to-convert-a-vtkmrmlscalarvolumenode-to-a-vtkmrmlsegmentationnode/20343/8 "2022-01-21T20:06:04Z")

</div>

If your scalar volume is already a binary labelmap (just imported as a scalar volume instead), then the easiest method is to convert your scalar volume to a labelmap using the Volumes module, in the “Volume Information” section:

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

and then import the labelmap as a segmentation using the “Segmentations” module in the “Export/Import models and labelmaps” section:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/1/51e176de0131840ff76405003d196654cfa00aee.png)

or programmatically using `ImportLabelmapToSegmentationNode` as suggested above.
