ANTsX / ANTs

Advanced Normalization Tools (ANTs)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AverageAffineTransform not working

Grace-93 opened this issue · comments

Describe the problem

I want to use AverageAffineTransform to average a group of affine matrices I got from antsRegistration. The resulting matrices seem in binary format and when I ran AverageAffineTransform, I got the error
"libc++abi: terminating with uncaught exception of type std::invalid_argument: stoi: no conversion".
I realized that AverageAffineTransform cannot process binary matrices.
Therefore, I used ConvertTransformFile to convert binary to text, but still got the same error.

To Reproduce

Run antsRegsitrtion as follow:
Screen Shot 2023-09-20 at 3 19 44 PM

Run ConvertTransformFile 3 inputBinaryTransform.mat outputTextTransform.txt to convert binary to text.

Then run

#!/bin/bash

for file in *.txt; do
    output_file="cleaned_${file}"
    # Extract the line with the transformation parameters and remove the "Parameters:" label
    grep "Parameters:" $file | sed 's/Parameters: //' > $output_file
    # Remove the line containing "Fixed"
    sed -i '' '/Fixed/d' $output_file
done

to take out the Parameter that is useful for AverageAffineTransform.

Finally, run AverageAffineTransform average_transform.txt input_matrix.txt

System information (please complete the following information)

  • OS: Mac OS, M1 chip
  • OS version: 12.2.1
  • Type of system: MacBook pro laptop

ANTs version information

  • ANTs code version: 2.4.4.dev
  • ANTs installation type: Compiled from source: Jun 24 2023 21:17:36

Additional information

I think you're missing a parameter, please see AverageAffineTransform without args to get usage.

It does support the binary .mat transforms, though the usage shows examples with .txt warps

Here's the usage:

AverageAffineTransform ImageDimension output_affine_transform [-R reference_affine_transform] {[-i] affine_transform_txt [weight(=1)] ]}

This works for me

AverageAffineTransform 3 avg.mat transform1_0GenericAffine.mat transform2_0GenericAffine.mat

Omitting the ImageDimension parameter raises the stoi error.

I'll update the usage to clarify that other transform formats than .txt are supported.