I have this working using c3d (I didn't use its fsl conversion, but it
would probably work and save two steps, as the inversion wouldn't be
needed).  The important bits follow.

Tim

c3d_affine_tool -itk ants_warpAffine.txt -o ants_affine_world.txt

#the affine it outputs is reverse (atlas coords to individual coords)
#wb_command world convention is a forward warp, so the output of the
wb_command conversion is the inverse of what fsl needs
wb_command -convert-affine \
    -from-world ants_affine_world.txt \
    -to-flirt "$subjdir"/ants_affine_flirt.txt \
        "$templatedir"/MNI152_T1_0.7mm.nii.gz \
        "$insubjdir"/T1w/T1w_acpc_dc_restore.nii.gz
convert_xfm \
    -inverse "$subjdir"/ants_affine_flirt.txt \
    -omat "$subjdir"/ants_affine_inv_flirt.txt

#apply X and Y flips to warpfields
#first negate all of them, then take the frames I need
wb_command -volume-math '-x' \
    ants_warponly_negative.nii.gz \
    -var x ants_warpWarp.nii.gz

wb_command -volume-merge \
    ants_warponly_world.nii.gz \
    -volume ants_warponly_negative.nii.gz \
        -subvolume 1 -up-to 2 \
    -volume ants_warpWarp.nii.gz \
        -subvolume 3

#affine already takes it into MNI space, so use MNI as ref for both sides
of warp
wb_command -convert-warpfield \
    -from-world ants_warponly_world.nii.gz \
    -to-fnirt "$subjdir"/ants_warponly_fnirt.nii.gz \
        "$templatedir"/MNI152_T1_0.7mm.nii.gz

#compose
convertwarp \
    --ref="$templatedir"/MNI152_T1_0.7mm.nii.gz \
    --premat="$subjdir"/ants_affine_inv_flirt.txt \
    --warp1="$subjdir"/ants_warponly_fnirt.nii.gz \
    --out="$subjdir"/ants_fullreg_fnirt.nii.gz

#resample to sanity check
applywarp \
    --ref="$templatedir"/MNI152_T1_0.7mm.nii.gz \
    --in="$insubjdir"/T1w/T1w_acpc_dc_restore.nii.gz \
    --warp="$subjdir"/ants_fullreg_fnirt.nii.gz \
    --out="$subjdir"/ants_reg_fnirt_resamp.nii.gz


On Fri, Feb 2, 2018 at 5:41 PM, Moises Hernandez Fernandez <
mois...@fmrib.ox.ac.uk> wrote:

> I had the same problem in the past... try:
> *c3d_affine_tool -itk ANTSmat.txt -ref myref -src mysrc -ras2fsl -o
> FSLmat.txt *
>
> However, as Tim said, this tool only converts the affine, not the warp.
>
> Moises.
>
>
>
> On 2 February 2018 at 18:33, Timothy Coalson <tsc...@mst.edu> wrote:
>
>> I haven't finished figuring this out, but it appears that the affine
>> file's "Parameters" array contains the 12 affine components you'd find in a
>> normal affine file.  The warpfield does not seem to include the affine, so
>> you need to convert and use both of them, which may be why what you did
>> looked wrong.
>>
>> Tim
>>
>>
>> On Fri, Feb 2, 2018 at 4:54 PM, Glasser, Matthew <glass...@wustl.edu>
>> wrote:
>>
>>> I think Tim Coalson might be playing with this right now.  Perhaps he
>>> can respond if there is a solution he figures out.
>>>
>>> Peace,
>>>
>>> Matt.
>>>
>>> From: <hcp-users-boun...@humanconnectome.org> on behalf of Anjani
>>> Bhargavi <anjaniragotha...@gmail.com>
>>> Date: Friday, February 2, 2018 at 4:36 PM
>>> To: "hcp-users@humanconnectome.org" <hcp-users@humanconnectome.org>
>>> Subject: [HCP-Users] Software to convert ANTs warps to FSL format
>>>
>>> Hi,
>>>
>>> Have any of you tried converting ANTs warps to FSL format? I tried doing
>>> it with c3d_affine_tool -ras2fsl option, but I wasn't not successful with
>>> it. I ended up with an error:
>>>
>>> terminate called after throwing an instance of 'char const*'
>>>
>>> Aborted                 (core dumped)
>>>
>>>
>>> I actually would like to convert the nonlinear warps. If there's a tool
>>> that any of you have used to do that, please let me know. I tried using the
>>> workbench command, convert-warpfield, to convert from world to fnirt
>>> format. The command worked, but when I used the warp to do the
>>> registration, the output didn't look like it actually worked. Any help is
>>> appreciated.
>>>
>>> --
>>> Thanks and Regards,
>>> Anjani Bhargavi.R
>>> If you have the willpower to do things nothing will be against you!
>>>
>>> _______________________________________________
>>> HCP-Users mailing list
>>> HCP-Users@humanconnectome.org
>>> http://lists.humanconnectome.org/mailman/listinfo/hcp-users
>>>
>>> _______________________________________________
>>> HCP-Users mailing list
>>> HCP-Users@humanconnectome.org
>>> http://lists.humanconnectome.org/mailman/listinfo/hcp-users
>>>
>>
>> _______________________________________________
>> HCP-Users mailing list
>> HCP-Users@humanconnectome.org
>> http://lists.humanconnectome.org/mailman/listinfo/hcp-users
>>
>
>

_______________________________________________
HCP-Users mailing list
HCP-Users@humanconnectome.org
http://lists.humanconnectome.org/mailman/listinfo/hcp-users

Reply via email to