Merge dicom or nrrd or nii images

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

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.

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.

See for example this post: Set target region for image resampling

@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))
1 Like

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

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) :slight_smile:

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?

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

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).

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.

1 Like

Just in case somebody comes across this topic now: @mikebind recently contributed the Stitch Volumes module for stitching multiple volumes into one. It is available in Sandbox extension.