How to merge two 3D label images ?

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!

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.

1 Like

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

The MaximumImageFilter would do this.

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.