# How to combine images

**URL:** https://discourse.itk.org/t/how-to-combine-images/5359
**Category:** Uncategorized
**Created:** [September 25, 2022, 3:36am UTC](https://discourse.itk.org/t/how-to-combine-images/5359 "2022-09-25T03:36:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![cnkhanh](https://discourse.itk.org/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@cnkhanh](https://discourse.itk.org/u/cnkhanh)
#### Post date: [September 25, 2022, 3:36am UTC](https://discourse.itk.org/t/how-to-combine-images/5359/1 "2022-09-25T03:36:33Z")

</div>

I have four images (1 channel): CT, airtree, vessels, lobes. I tried to combine as below,

```auto
ref_img = sitk.ReadImage("data/ct.hdr", sitk.sitkInt8)
vessel_img = sitk.ReadImage("data/vessels.hdr", sitk.sitkInt8)
airway_img = sitk.ReadImage("data/airtree.hdr", sitk.sitkInt8)
lobe_img = sitk.ReadImage("data/lobes.hdr", sitk.sitkInt8)

vessel_resampled = sitk.Resample(vessel_img, ref_img)
airway_resampled = sitk.Resample(airway_img, ref_img)
lobe_resampled = sitk.Resample(lobe_img, ref_img)

combined = sitk.Compose(ref_img, vessel_resampled, airway_resampled, lobe_resampled)

sitk.WriteImage(combined, "output/composed.hdr")

```

But the output image just likes the stack of four images (it has 4 channels).  
How to combine these images into 1 channel image.

---

<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: [September 26, 2022, 1:08pm UTC](https://discourse.itk.org/t/how-to-combine-images/5359/2 "2022-09-26T13:08:14Z")

</div>

Hello,

> How to combine these images into 1 channel image.

What are the images you have? Perhaps “ct.hdr” is a 16-bit CT scan and the other there are binary labels ( 0 and non-zero for the feature)? If the labels are overlapping there is more complexity.

The first step would be to combine the multiple binary label images into a single image label image with multiple values representing each label.

```auto
vessel_label = 1
airway_label = 2
lobe_label = 3
label_img = sitk.NaryMaximum( (vessel_img != 0)*vessel_label,
                                                    (airway_img != 0) * airway_label,
                                                    (lobe_img != 0) * lobe_label)

```

Then the label image can be overplayed the gray scale CT:

```auto
output = sitk.LabelOverlay(ref_img, label_img)

```

Needless to say I have not run this code with your data so there may be some casting of pixel types or other minor operations needed.
