# Merging two different segmentations/models

**URL:** <https://discourse.slicer.org/t/merging-two-different-segmentations-models/30047>\
**Category:** Support\
**Created:** [June 15, 2023, 9:18am UTC](https://discourse.slicer.org/t/merging-two-different-segmentations-models/30047 "2023-06-15T09:18:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![umgpy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/umgpy/32/18240_2.png) [@umgpy](https://discourse.slicer.org/u/umgpy)\
**Post date:** [June 15, 2023, 9:18am UTC](https://discourse.slicer.org/t/merging-two-different-segmentations-models/30047/1 "2023-06-15T09:18:35Z")

</div>

I have surface model along with it’s segmentation to this I want to merge another segmentation which is not in the same segmentation node. Due to this the merge function in segmentation editor model does not work.

Is there a way to either move the segmentation within the other so that the merge operation can take place. Or is there another way to this?

Additionally I would like to process this as a batch operation.

I am unable to attach a screenshot to provide a little more context, if needed I can do so through other image services.

Thanks in advance and a greetings to everyone at the Project week!

---

<div class="post-metadata">

**Author:** ![S\_Arbabi](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@S\_Arbabi](https://discourse.slicer.org/u/S_Arbabi)\
**Post date:** [June 15, 2023, 9:38am UTC](https://discourse.slicer.org/t/merging-two-different-segmentations-models/30047/2 "2023-06-15T09:38:32Z")

</div>

I think you can do this by:  
1-converting each segmentation into a labelmap  
segmentationLblmap = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLLabelMapVolumeNode”)  
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, segmentationLblmap, reference\_volume\_node)  
2-getting the array of each segmentation  
array1 = slicer.util.arrayFromVolume(segmentationLblmap)  
3-do a boolean OR operation between two arrays  
arrayOR = np.logical\_or(array1.astype(bool), array2.astype(bool)).astype(int)  
4- update a labelmap volume from the new array  
slicer.util.updateVolumeFromArray(segmentationLblmap, arrayOR)  
5- save the labelmap node as a segmentation  
slicer.util.saveNode(segmentationLblmap, “d:/…nii.gz”)

Saeed

---

<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:** [June 19, 2023, 1:03pm UTC](https://discourse.slicer.org/t/merging-two-different-segmentations-models/30047/3 "2023-06-19T13:03:29Z")

</div>

If the previous answer is not satisfactory to you, can you please tell us more about the exact data objects? It is not clear to me. A screenshot of the Data module would suffice. No need to use an image service, just drag&drop the screenshot here.
