FSL warp to ANTs (nii.gz to .h5)

Dear all,

I have some transformations calculated using a combination of FSL and ANTs. They have been merged into one final warp interpretable to FSL (using wb_command -convert-warpfield). This transformation contains some warps and affine transformations. I would like to convert it to itk (ants interpretable), .h5 to be more precise. Is there any possibility to do this? Thanks in advance.

Best regards,

Manuel

Hi,

c3d may be your friend there. I never tried myself for warps, I know it works well for affine transforms.

This discussion may be of interest for you:
https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=fsl;c21935f9.1901

Let us know if you find a solution that works for you! Thanks!

Julien

Hi Manuel,

I am having the same issue here. I am trying to convert a warpfield generated by FNIRT to a ANTs readable format (as you suggested, .h5 file could be a way to go), but using wb_command -convert-warpfield -from-fnirt {input} {source} -to-itk {output} generates a .nii.gz file, which ANTs is not able to recognise.

In my case I am using the antsApplyTransforms command, where I would like to include the file I am trying to convert as a --transform file to perform a registration. The following exception is raised:

Transform reader for {path_to_file}/non-linear_warp-coeffs_postt1w_to_pret1w_ants_format.nii.gz caught an ITK exception:

itk::ExceptionObject (0x5f0bab1ac440)
Location: "unknown" 
File: /home/runner/work/_temp/build/ITKv5/Modules/IO/TransformBase/src/itkTransformFileReader.cxx
Line: 128
Description: ITK ERROR: TransformFileReaderTemplate(0x5f0bab1c5790): Could not create Transform IO object for reading file {path_to_file}/non-linear_warp-coeffs_postt1w_to_pret1w_ants_format.nii.gz
  Tried to create one of the following:
    HDF5TransformIOTemplate
    HDF5TransformIOTemplate
    MINCTransformIOTemplate
    MINCTransformIOTemplate
    MatlabTransformIOTemplate
    MatlabTransformIOTemplate
    TxtTransformIOTemplate
    TxtTransformIOTemplate
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.

I have found that the c3d_affine_tool is useful in certain cases similar to this one, but as these warpfields refer to non-linear transformations, affine matrices are not the way to go here.

I am not able to use ConvertTransformFile either, as there is no way that ANTs understands this .nii.gz file that the Connectome Workbench is giving me as an output. I am reviving this topic as it was very difficult for me to find another ongoing thread here or elsewhere dealing with this same issue. I hope you can remember/recollect any useful information/scripts that you were using at that time and give me a hand :). Thank you in advance,

Doneka

Hi @donekaloinaz , can you post the header of the problem file?

PrintHeader {path_to_file}/non-linear_warp-coeffs_postt1w_to_pret1w_ants_format.nii.gz

This might help diagnose why it’s not being read as a displacement field.

Hi @cookpa , I was finally able to work around it creating the registration files directly with ANTs. Either way, I would be interested in solving this problem.

So printing the header from the file giving the problem gives an error by PrintHeader, as it cannot read the file. However, I hereby paste the information printed by PrintHeader from the input file for the wb_command command:

WARNING: In /home/runner/work/_temp/build/ITKv5/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx, line 2033
NiftiImageIO (0x57cd5f7432e0): non-linear_warp-coeffs_postt1w_to_pret1w_fnirt_format.nii.gz has unexpected scales in sform

WARNING: In /home/runner/work/_temp/build/ITKv5/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx, line 2033
NiftiImageIO (0x57cd5f74c2d0): non-linear_warp-coeffs_postt1w_to_pret1w_fnirt_format.nii.gz has unexpected scales in sform

 Spacing [10, 10, 10, 1]
 Origin [-176, -256, 256, 0]
 Direction 
-1 0 0 0
0 -1 0 0
0 0 1 0
0 0 0 1

 Size : [20, 28, 28, 3]

  Image Dimensions   : [20, 28, 28, 3]
  Bounding Box       : {[-176 -256 256 0], [24 24 536 3]}
  Voxel Spacing      : [10, 10, 10, 1]
  Intensity Range    : [-15.4926, 15.1134]
  Mean Intensity     : -0.0443095
  Direction Cos Mtx. : 
-1 0 0 0
0 -1 0 0
0 0 1 0
0 0 0 1

  Voxel->RAS x-form  : 
  Image Metadata: 
    ITK_FileNotes = 2203.12-dirty 2024-02-01T16:17:47+00:00
    ITK_original_direction of unsupported type N3itk6MatrixIdLj4ELj4EEE
    ITK_original_spacing of unsupported type St6vectorIdSaIdEE
    ITK_sform_corrected = NO
    bitpix = 32
    cal_max = 0
    cal_min = 0
    datatype = 16
    descrip = 2203.12-dirty 2024-02-01T16:17:47+00:00
    dim[0] = 4
    dim[1] = 20
    dim[2] = 28
    dim[3] = 28
    dim[4] = 3
    dim[5] = 1
    dim[6] = 1
    dim[7] = 1
    dim_info = 0
    intent_code = 2007
    intent_p1 = 1
    intent_p2 = 1
    intent_p3 = 1
    nifti_type = 1
    pixdim[0] = 0
    pixdim[1] = 10
    pixdim[2] = 10
    pixdim[3] = 10
    pixdim[4] = 1
    pixdim[5] = 1
    pixdim[6] = 1
    pixdim[7] = 1
    qfac = 1
    qform_code = 1
    qform_code_name = NIFTI_XFORM_SCANNER_ANAT
    qoffset_x = 176
    qoffset_y = 256
    qoffset_z = 256
    qto_xyz of unsupported type N3itk6MatrixIfLj4ELj4EEE
    quatern_b = 0
    quatern_c = 0
    quatern_d = 0
    scl_inter = 0
    scl_slope = 1
    sform_code = 1
    sform_code_name = NIFTI_XFORM_SCANNER_ANAT
    slice_code = 0
    slice_duration = 0
    slice_end = 0
    slice_start = 0
    srow_x = 1.00173 -0.00187141 -0.00343273 0.646828
    srow_y = 0.00299998 0.998577 0.00443622 -0.63103
    srow_z = 0.00343532 -0.00315679 0.997102 0.772982
    toffset = 0
    vox_offset = 352
    xyzt_units = 10

I may be misusing the wb_command from the workbench in order to get what I need?

I’m not sure how wb_command works, but I think the image you have here is fnirt coefficients, not displacement vectors. I can tell by the intent code (2007) and the low resolution of the image (spacing=10mm). I don’t know if wb_command can handle these or if it needs a displacement field, which you’d get with --fout=warpfield.nii.gz in fnirt