May I know how Nifti1Image(data, affine, header) does exactly?

I have been trying to downsample the diffusion data of HCP from 1.25X1.25X1.25 - 1.5X1.5X1.5. I am using dipy resample for the downsampling. However, when I compare the header files of both I can see that the pixdim last 3 positions are 0 in the original dataset, however they are 1 in the downsampled one? Can I get any idea on this?

A valid NIfTI image should specify the distance between voxel centers as lixdim[1],[2],[3] for column, row and slice. If the original dataset lists these as 0, I would be extremely concerned and suggest you go back to your source data (e.g. how did you convert the HCP DICOM data to NIfTI) to ensure you have proper NIfTI files. In theory, there is some redundancy, as the SForm and QForm should also provide spatial information that could be used to recover the lixdim values. For example, if I inspect the header of sag_int_36sl_21.nii you can see that the row, column and slice spacing is reported in both lixdim as well as the storm (though you may need to do a vector by matrix multiply if your image was acquired obliquely to the scanner bore):

fslhd sag_int_36sl_21.nii
...
pixdim1		3.250000
pixdim2		3.250000
pixdim3		3.600000
...
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	0.000000 0.000000 -3.600000 63.000000 
sto_xyz:2	-3.250000 0.000000 0.000000 140.319641 
sto_xyz:3	0.000000 3.250000 0.000000 -126.173706 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Anterior-to-Posterior
sform_yorient	Inferior-to-Superior
sform_zorient	Right-to-Left

My own sense is to make sure you start with good data. If your original data does not report the pixdim, I would worry about other more insidious issues.

I would also be really careful about downsampling images. You will need to apply an algorithm that handles anti-aliasing. See the [notebook]((Subsample NIfTI - #3 by Chris_Rorden) created by @satra for details. Briefly, when you downsample images, low frequencies can masquerade as higher frequencies - the same reason why car wheel spokes can appear to rotate backwards on TV commercials.

Hi,

Thanks a lot for the reply. However, I would like to mention that pixdim[1] = pixdim[2] = pixdim[3] = 1.25 in the original dataset header and they are 1.5 in the downsampled one, which is required. I am talking pixdim[5] = pixdim[6] = pixdim[7] = 0 in the original dataset header, however they are 1 in the downsampled one. Also, the data is 4-dimensional as specified by dim[0] = 4. May I know why is this happening? Means, the pixdim[5,6,7] become 1 after downscaling. Can they have any effect?

Also, for the downscaling, I am using this: from dipy.align.reslice import reslice. May I know if I have to be careful about anti-aliasing?

Hi,

Thanks a lot for the reply. However, I would like to mention that pixdim[1] = pixdim[2] = pixdim[3] = 1.25 in the original dataset header and they are 1.5 in the downsampled one, which is required. I am talking pixdim[5] = pixdim[6] = pixdim[7] = 0 in the original dataset header, however they are 1 in the downsampled one. Also, the data is 4-dimensional as specified by dim[0] = 4. May I know why is this happening? Means, the pixdim[5,6,7] become 1 after downscaling. Can they have any effect?

Unused dimensions will have no impact.

Technical details on the NIfTI header are here.

Briefly, dim[0] defines the number of dimensions, so if dim[0]=4 then only the there are only four dimensions (column, row, slices, volumes) defined in dim[1…4], with the spacing between voxels being in pixdim[1…4]. The values of of the other values is undefined (e.g. the values in dim[5…7] and pixdim[5…7]). However, it is good practice to set the unused values of dim[] = 1, as older versions of Matlab assume the number of voxels is the product of dim[1…7]. Presumably, the downsampling code you are using used the same logic to set the unused pixdim[] = 1.

As a concrete example, consider this 4D datasets: it is 64*64*35*2 Columns*Rows*Slices*Volumes with the voxel centers 3.253.253.25mm apart and the volumes 3 seconds apart.

$fslhd ax_desc_35sl_7.nii
filename	ax_desc_35sl_7.nii

sizeof_hdr	348
data_type	INT16
dim0		4
dim1		64
dim2		64
dim3		35
dim4		2
dim5		1
dim6		1
dim7		1
...
bitpix		16
pixdim0		-1.000000
pixdim1		3.250000
pixdim2		3.250000
pixdim3		3.600000
pixdim4		3.000000
pixdim5		0.000000
pixdim6		0.000000
pixdim7		0.000000
...
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	-3.250000 0.000000 -0.000000 104.000000 
sto_xyz:2	0.000000 3.230991 -0.388798 -58.684311 
sto_xyz:3	0.000000 0.350998 3.578943 -84.798035 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Right-to-Left
sform_yorient	Posterior-to-Anterior
sform_zorient	Inferior-to-Superior
file_type	NIFTI-1+

By the way, since NIfTI images include a spatial transformation matrix, pixdim[1…3] can derived from the magnitude of the 3D vectors in the SForm. Finally, the value of pixdim[0] is important if the QForm is set (it is the qfac for handling negative determinants).