# How to merge two 3D label images ?

**URL:** https://discourse.itk.org/t/how-to-merge-two-3d-label-images/4149
**Category:** Uncategorized
**Created:** [May 23, 2021, 11:20pm UTC](https://discourse.itk.org/t/how-to-merge-two-3d-label-images/4149 "2021-05-23T23:20:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Hugo](https://discourse.itk.org/user_avatar/discourse.itk.org/hugo/32/2011_2.png) [@Hugo](https://discourse.itk.org/u/Hugo)
#### Post date: [May 23, 2021, 11:20pm UTC](https://discourse.itk.org/t/how-to-merge-two-3d-label-images/4149/1 "2021-05-23T23:20:46Z")

</div>

I have two sources for labels on the same scan.

img1 contains labels [0, 1, 4] and img2 contains labels [0, 2, 3].

Those two images are coregistered, and I’d like to transfer the labels from img2 to img1.

So I have one 3D image with all the labels [0, 1, 2, 3, 4]

I couldn’t figure it out, please advise me !

Thanks!

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [May 24, 2021, 11:43am UTC](https://discourse.itk.org/t/how-to-merge-two-3d-label-images/4149/2 "2021-05-24T11:43:42Z")

</div>

Hello,

Are the labels overlapping? If not the two images could simply be added together. If they do overlay, the labels could simply be merged with a min or max image filter.

---

<div class="post-metadata">

### Author: ![Hugo](https://discourse.itk.org/user_avatar/discourse.itk.org/hugo/32/2011_2.png) [@Hugo](https://discourse.itk.org/u/Hugo)
#### Post date: [May 24, 2021, 4:47pm UTC](https://discourse.itk.org/t/how-to-merge-two-3d-label-images/4149/3 "2021-05-24T16:47:17Z")

</div>

This is a good answer,

How about if I want to have a preferential order in case of a conflict ?

Let’s say, 4 \> 2 \> 3 \> 1 or anything like that. Meaning, If a label overlap I would choose according to that order.

Thank you very much

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [May 24, 2021, 5:11pm UTC](https://discourse.itk.org/t/how-to-merge-two-3d-label-images/4149/4 "2021-05-24T17:11:32Z")

</div>

> [@Hugo](#):
>
> Let’s say, 4 \> 2 \> 3 \> 1 or anything like that. Meaning, If a label overlap I would choose according to that order.

The MaximumImageFilter would do this.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)
#### Post date: [May 24, 2021, 5:30pm UTC](https://discourse.itk.org/t/how-to-merge-two-3d-label-images/4149/5 "2021-05-24T17:30:23Z")

</div>

If you need anything more fancy than minimum or maximum operator then you can get the volumes as numpy arrays and combine them using any Python function.
