Hi there! I am new to ants and I wonder if anyone has encountered this little and probably very trivial issue.
Summary of what happened:
I am trying to combine motion correction and normalization for PET images as suggested here: Aligning PET data to MNI space using FMRIPREP transform. The idea is that this would reduce the number of times I need to reslice the data from 2 to 1. The code runs and I get a nice list of images, but I somehow can’t combine the images with ants.list_to_ndimage()
.
The frames_in_MNI
looks like this:
[ANTsImage (LPI)
Pixel Type : float (float32)
Components : 1
Dimensions : (91, 109, 91)
Spacing : (2.0, 2.0, 2.0)
Origin : (90.0, 126.0, -72.0)
Direction : [-1. 0. 0. 0. -1. 0. 0. 0. 1.],
ANTsImage (LPI)
Pixel Type : float (float32)
Components : 1
Dimensions : (91, 109, 91)
Spacing : (2.0, 2.0, 2.0)
Origin : (90.0, 126.0, -72.0)
Direction : [-1. 0. 0. 0. -1. 0. 0. 0. 1.],
...
I have no idea what must give a origin value for each dimension (4)
refers to. When doing motion correction as shown here: ANTsPy/tutorials/motionCorrectionExample.ipynb at master · ANTsX/ANTsPy · GitHub, the list motion_corrected
also has only 3 values, eg. print(motion_corrected[0].origin)
(-358.8940124511719, -359.4070129394531, 128.38400268554688)
Thanks in advance!
Command used (and if a helper script was used, a link to the helper script or the command generated):
T1w2MNI = glob.glob(f'{bids_dir}/{subject}/{session}/anat/*MNI152NLin6Asym_mode-image_xfm.h5')[0]
PET2T1W =f'{regdir}/fwdtransform_PET2T1w_Affine.mat'
# motion_affines is a list of affines saved when motion correcting the PET
images_unmerged = ants.ndimage_to_list( pet )
frames_in_MNI = list()
for i in range(len(images_unmerged)):
comb_transforms = ants.apply_transforms(fixed=T1w_MNI,
moving=images_unmerged[i],
transformlist=[ T1w2MNI, PET2T1W, motion_affines[i]],
compose=regdir)
frame_MNI = ants.apply_transforms(fixed=T1w_MNI,moving=images_unmerged[i],transformlist=[comb_transforms])
frames_in_MNI.append( frame_MNI )
mc_MNI_PET = ants.list_to_ndimage( T1w_MNI, frames_in_MNI )
Version:
ants.version
‘0.5.3’
Relevant log outputs (up to 20 lines):
ValueError Traceback (most recent call last)
Cell In[77], line 12
8 frame_MNI = ants.apply_transforms(fixed=T1w_MNI,moving=images_unmerged[i],transformlist=[comb_transforms])
9 frames_in_MNI.append( frame_MNI )
---> 12 mc_MNI_PET = ants.list_to_ndimage( T1w_MNI, frames_in_MNI )
File ~/.local/lib/python3.11/site-packages/ants/utils/ndimage_to_list.py:48, in list_to_ndimage(image, image_list)
45 raise ValueError('all images must have the same pixeltype')
47 dimensionout = ( *image_list[0].shape, len( image_list ) )
---> 48 newImage = ants.make_image(
49 dimensionout,
50 spacing = ants.get_spacing( image ),
51 origin = ants.get_origin( image ),
52 direction = ants.get_direction( image ),
53 pixeltype = inpixeltype
54 )
55 # FIXME - should implement paste image filter from ITK
56 for x in range( len( image_list ) ):
File ~/.local/lib/python3.11/site-packages/ants/core/ants_image_io.py:215, in make_image(imagesize, voxval, spacing, origin, direction, has_components, pixeltype)
213 else:
214 array = np.full(imagesize, voxval, dtype="float32")
--> 215 image = from_numpy(
216 array,
...
167 if len(new_origin) != self.dimension:
--> 168 raise ValueError('must give a origin value for each dimension (%i)' % self.dimension)
170 get_lib_fn('setOrigin')(self.pointer, new_origin)
ValueError: must give a origin value for each dimension (4)