# Segmentation Alignment

**URL:** <https://discourse.slicer.org/t/segmentation-alignment/13449>\
**Category:** Support\
**Created:** [September 11, 2020, 7:32pm UTC](https://discourse.slicer.org/t/segmentation-alignment/13449 "2020-09-11T19:32:45Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoomi](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yoomi](https://discourse.slicer.org/u/yoomi)\
**Post date:** [September 11, 2020, 7:32pm UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/1 "2020-09-11T19:32:45Z")

</div>

Hi everyone,

I have a pre-determined VOI segmentation and DCE MRI sequence in DICOM format, and want to overlay/align them. What is the best way to go about this? I was thinking about converting the VOI segmentation to a labelmap volume matched to reference geometry of the DCE MRI’s. Would this work to align?

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, 2:00am UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/2 "2020-09-12T02:00:22Z")

</div>

Yes, you should be able to load the segmentation as a segmentation node and the MRI as a volume node and Slicer will overlay them correctly. There are many visualization parameters that you can tune in Segmentations module’s Display section.

---

<div class="post-metadata">

**Author:** ![yoomi](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yoomi](https://discourse.slicer.org/u/yoomi)\
**Post date:** [September 13, 2020, 12:03am UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/3 "2020-09-13T00:03:17Z")

</div>

Hi Andras,

When I try to do this, I load the MRI as a volume using slicer.util.loadVolume(), and then want to use the code below. However, I’m not sure how to (1) get the MRML node of the loaded MRI volume and (2) load the segmentation before getting the segmentation node as below. Thanks!

```python
segmentationNode = getNode('Segmentation')
labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLabelMapVolumeNode')
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, labelmapVolumeNode, referenceVolumeNode)

```

---

<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 13, 2020, 12:48am UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/4 "2020-09-13T00:48:17Z")

</div>

Does everything work correctly using the GUI?

What are the input files on disk that you would like to load using Python?

---

<div class="post-metadata">

**Author:** ![yoomi](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yoomi](https://discourse.slicer.org/u/yoomi)\
**Post date:** [September 15, 2020, 1:56am UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/5 "2020-09-15T01:56:28Z")

</div>

Hi Andras,

I am able to load the MRI dicom’s as a volume, but I am having trouble loading the segmentation. The segmentation file is also in dicom format, so I am trying to load as labelmap through GUI following instructions ([https://slicer.readthedocs.io/en/latest/user\_guide/modules/segmentations.html](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmentations.html)) but I don’t see this option. What do you recommend?

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 15, 2020, 3:35am UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/6 "2020-09-15T03:35:31Z")

</div>

> [@yoomi](#):
>
> The segmentation file is also in dicom format

What information object is used for storing the segmentation: DICOM RT structure set or DICOM Segmentation Object?

---

<div class="post-metadata">

**Author:** ![yoomi](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yoomi](https://discourse.slicer.org/u/yoomi)\
**Post date:** [September 15, 2020, 3:37am UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/7 "2020-09-15T03:37:48Z")

</div>

DICOM segmentation object

---

<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 15, 2020, 3:39am UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/8 "2020-09-15T03:39:57Z")

</div>

DICOM segmentation object must be loaded via DICOM module and it requires Quantitative Reporting extension.

---

<div class="post-metadata">

**Author:** ![yoomi](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yoomi](https://discourse.slicer.org/u/yoomi)\
**Post date:** [September 15, 2020, 3:52am UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/10 "2020-09-15T03:52:58Z")

</div>

Hi Andras,

Please ignore my last reply, I was able to get it to work by putting the seg files in the same folder. The new problem I have is that 2 of the segmentation files (specifically PE segmentations) are not able to load as a DICOMsegmentation-- do you know why this could be? 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 15, 2020, 4:07am UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/11 "2020-09-15T04:07:48Z")

</div>

Use the latest Slicer Preview Release. If the import still does not work as expected then check if there are any errors or warnings in the log.

---

<div class="post-metadata">

**Author:** ![yoomi](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yoomi](https://discourse.slicer.org/u/yoomi)\
**Post date:** [September 23, 2020, 1:33pm UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/12 "2020-09-23T13:33:04Z")

</div>

Hi Andras,

Luckily this worked – thank you. I have a follow - up question: to export a labelmap volume (based on the aligned MRI volume reference geometry with the segmentation file) to a file, what are the settings I should use in the segmentations module? Thank you

---

<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 23, 2020, 3:06pm UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/13 "2020-09-23T15:06:48Z")

</div>

In general, if you don’t need any special behavior, use default settings. To set a reference geometry for export, select the reference volume in Segmentations module / Export/import… / Advanced / Reference volume.

---

<div class="post-metadata">

**Author:** ![yoomi](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yoomi](https://discourse.slicer.org/u/yoomi)\
**Post date:** [September 23, 2020, 3:13pm UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/14 "2020-09-23T15:13:41Z")

</div>

What is the difference between the section to “export/import models and labelmaps” and “export to files”?

---

<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 23, 2020, 3:31pm UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/15 "2020-09-23T15:31:04Z")

</div>

Export/import models and labelmaps exports to nodes in the scene (that you can later save to files using Save data… window). “Export to files” saves directly to files.

@Sunderlandkyl what geometry is used by “Export to files” when exporting nrrd/nifti? Probably we should add a reference volume selector there, too.

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [September 23, 2020, 3:45pm UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/16 "2020-09-23T15:45:58Z")

</div>

Export to file currently uses the reference geometry string. I believe it’s the same with both export to labelmap and export to files (with the exception of the reference volume selector). I’ll add a combo box to choose the reference volume.

---

<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 23, 2020, 4:13pm UTC](https://discourse.slicer.org/t/segmentation-alignment/13449/17 "2020-09-23T16:13:06Z")

</div>

> [@Sunderlandkyl](#):
>
> I’ll add a combo box to choose the reference volume.

That would be great, thank you!
