I have a set of DICOM cardiac images with 14 short axis slices, 3 (3 chamber view slices), and 3 (4 chamber view) slice images respectively. I am trying to create a single nifti file that combines these 3 views and their respective slices into a single volume file that can be opened in 3D slicer.
Here is a dropbox link to an example of anonymized images I'm working with.
Folder series1 are the axial images, series 2 are the (3 chamber view images), and series3 are the (4 chamber view images).
I have tried the following code. This takes the 3 series information from each time-step creates a nifti file for each series through dicom2nifti and attempts to combine the 3 niftis into one single nifti file for the entire volume. I'm fairly new to python but I am using the nipype.interfaces.fsl.merge function for this operation
import os
import tempfile
import dicom2nifti
from nipype.interfaces.fsl import Merge
totalTimeStep = 20
path = r'C:\Users\owenb\Dropbox\BaenenProject\1Owen23\TestData\CASE1\dicomData'
outputDir = r'C:\Users\owenb\Dropbox\BaenenProject\1Owen23\TestData\CASE1\nifti data'
for i in range(1, totalTimeStep + 1):
timeFolderPath = os.path.join(path, 't' + str(i))
output = os.path.join(outputDir, 't' + str(i))
s1 = os.path.join(timeFolderPath, 'series1')
s2 = os.path.join(timeFolderPath, 'series2')
s3 = os.path.join(timeFolderPath, 'series3')
with tempfile.TemporaryDirectory() as tempPath:
dicom2nifti.settings.disable_validate_slicecount()
dicom2nifti.convert_directory(s1, tempPath, compression=True, reorient=True)
dicom2nifti.convert_directory(s2, tempPath, compression=True, reorient=True)
dicom2nifti.convert_directory(s3, tempPath, compression=True, reorient=True)
files = os.listdir(tempPath)
s1path = os.path.join(tempPath,files[0])
s2path = os.path.join(tempPath,files[1])
s3path = os.path.join(tempPath,files[2])
outputTimeStep = os.path.join(outputDir, 't'+str(i))
# Construct the fslmerge command s1 = axial, s2 = 3 chamberview, s3 = 4 chamber view
merger = Merge()
merger.inputs.in_files = [s1path, s2path, s3path]
merger.inputs.dimension = 'xyz'
merger.inputs.merged_file = outputTimeStep
I get the following error message
TraitError: The 'dimension' trait of a MergeInputSpec instance
must be 't' or 'x' or 'y' or 'z' or 'a',
but a value of 'xyz' <class 'str'> was specified.
How can I perform this nifti file merging while maintaining the orthogonality of the planes?