# Merge dicom or nrrd or nii images

**URL:** <https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [November 30, 2017, 4:46pm UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566 "2017-11-30T16:46:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Frenzel](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Daniel\_Frenzel](https://discourse.slicer.org/u/Daniel_Frenzel)\
**Post date:** [November 30, 2017, 4:46pm UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/1 "2017-11-30T16:46:21Z")

</div>

I want to merge sub-MRI images of a patient to one bigger file.  
I noticed that neither MITK nor ITK-Snap are suitable to merge images.  
C3d also fails because the sub-images have different sizes.  
Is it possible to merge MRI images anyhow?

Operating system: Windows  
Slicer version:4.8

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 30, 2017, 5:11pm UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/2 "2017-11-30T17:11:21Z")

</div>

It takes a couple of steps but it is certainly possible.

- First you need to create an image that is large enough to contain the merged image. To achieve this, create a large enough ROI that contains all the images and use `Crop Volume` module grow the first image to the size of this ROI (you need to enable `Interpolated cropping` to allow an image to grow beyond its original size).
- You can merge these images by simply adding them using Add scalar volumes module. If the images overlap then you can blank out overlapping region in one of the image using Segment `Editor module`'s `Mask Volume` effect (available in SegmentEditorExtraEffects extension).

Most likely you’ll see seams at the boundary of the two image. You can reduce that by image registration (if there is enough image overlap; using SlicerElastix extension), but for a seamless image you need to blending with gradually changing weight (alpha channel). To get this seamless image, create a binary mask by thresholding (Threshold scalar volume module) then smooth it (Gaussian blur image filter). You can then write a few-line Python script that appends alpha channel to your scalar volume and blends the images (using vtkImageBlend and (using vtkImageAppend filter). It may sound complicated but all these steps can all be done fully automatically by a few ten lines of Python script.

---

<div class="post-metadata">

**Author:** ![Daniel\_Frenzel](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Daniel\_Frenzel](https://discourse.slicer.org/u/Daniel_Frenzel)\
**Post date:** [December 1, 2017, 8:54am UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/3 "2017-12-01T08:54:40Z")

</div>

I haven’t used slicer 3D before, because I used MITK. I was just reading that slicer may have the possibility to do so. However, I am not sure where to define ROIs in 4.8. Using google sends me to a version 3 documentation.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 1, 2017, 12:20pm UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/4 "2017-12-01T12:20:45Z")

</div>

See for example this post: [Set target region for image resampling](https://discourse.slicer.org/t/set-target-region-for-image-resampling/894/2?u=lassoan)

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [February 26, 2020, 8:00am UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/6 "2020-02-26T08:00:44Z")

</div>

@lassoan if this is still not available, I think I will try to make an extension for this. I may need this feature in my work.

Here is the idea:

1. get the size, spacing, and origin, datatype of the input images.
  - we create a copy of the high-quality image and resample it to the second less quality image.
  - or we do the opposite, this could be user input.

2. create a new large image using information from step 1
3. add the resampled image and the second image to the larger image.
  - this should use a modified version of add scalar e.g. new image(x,y,z) = max(image1(x,y,z),image2(x,y,z))

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 26, 2020, 12:25pm UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/7 "2020-02-26T12:25:44Z")

</div>

Sounds good! Use latest Slicer Preview Release and “scripteddesigner” module template in Extension Wizard.

---

<div class="post-metadata">

**Author:** ![thomshaw92](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thomshaw92/32/5009_2.png) [@thomshaw92](https://discourse.slicer.org/u/thomshaw92)\
**Post date:** [May 14, 2021, 1:21am UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/8 "2021-05-14T01:21:29Z")

</div>

Hey @brhoom did you ever complete this?  
Would be great to be able to use it (i have 5 slabs of the same participant that need to be stitched together) 🙂

---

<div class="post-metadata">

**Author:** ![doc-xie](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@doc-xie](https://discourse.slicer.org/u/doc-xie)\
**Post date:** [October 26, 2021, 1:48am UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/9 "2021-10-26T01:48:19Z")

</div>

Hi Lassoan,  
I have merged the two volumes with Crop Volume-SegmentEditor-Add scalar Volumes modules with your advice. After the two volumes of the same patient were combined together, the result had different HU in bone or brain tissue.  
What the problem about this? Is there any error in the steps?  
Thanks!

 ![Screenshot](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/e/fe6931856a5a64311a148d818c381acafc65a9b8.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 26, 2021, 3:29am UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/10 "2021-10-26T03:29:26Z")

</div>

Do you have different intensity values in the combined volume than in the original volumes?

---

<div class="post-metadata">

**Author:** ![doc-xie](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@doc-xie](https://discourse.slicer.org/u/doc-xie)\
**Post date:** [October 26, 2021, 6:46am UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/11 "2021-10-26T06:46:31Z")

</div>

Hi Lassoan,  
The scalar range of one volume is -1024~1947 and the other is -1024~3071. Before combination, the Window/Level of them were all set to CT-brain in Volume module. But the superior part and the inferior part were shown in different intensity(superior in CT- brain, inferior in CT-bone).  
Thanks,  
Dr.Xie

---

<div class="post-metadata">

**Author:** ![doc-xie](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@doc-xie](https://discourse.slicer.org/u/doc-xie)\
**Post date:** [October 28, 2021, 1:08am UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/12 "2021-10-28T01:08:19Z")

</div>

Hi Lassoan,  
I have solved the issue with Crop Volumes and Add Scalar Volumes module. Maybe the problem about the different intensity is the improper size of the ROI.  
Thanks,  
Dr.Xie

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 20, 2022, 3:10pm UTC](https://discourse.slicer.org/t/merge-dicom-or-nrrd-or-nii-images/1566/13 "2022-10-20T15:10:43Z")

</div>

Just in case somebody comes across this topic now: @mikebind recently contributed the [Stitch Volumes module](https://github.com/PerkLab/SlicerSandbox#stitch-volumes) for stitching multiple volumes into one. It is available in Sandbox extension.
