How to combine images

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

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.


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.

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:

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.