Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ITK ERROR: ITK only supports orthonormal direction cosines" when using antsRegistrationSyN.sh #1675

Closed
ramBrain opened this issue Feb 8, 2024 · 13 comments

Comments

@ramBrain
Copy link

ramBrain commented Feb 8, 2024

Hi everyone,

I am trying to generate a transformation using antsRegistrationSyN.sh, but there seems to be an issue with one of the MRIs. Specifically, I get this error:

WARNING: In /usr/local/ANTs/build/ITKv5/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx, line 1934
NiftiImageIO (0x560b169efbb0): ../defT1_bs.nii has unexpected scales in sform

Exception caught during reference file reading 

itk::ExceptionObject (0x560b169c95b0)
Location: "unknown" 
File: /usr/local/ANTs/build/ITKv5/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx
Line: 2016
Description: ITK ERROR: ITK only supports orthonormal direction cosines.  No orthonormal definition found!

 file ../defT1_bs.nii
Exception Object caught: 

itk::ExceptionObject (0x560b169c95b0)
Location: "unknown" 
File: /usr/local/ANTs/build/staging/include/ITK-5.4/itkCenteredTransformInitializer.hxx
Line: 35
Description: ITK ERROR: CenteredTransformInitializer(0x560b169ebcd0): Moving Image has not been set

By checking the header, the sform looks like this:

sto_xyz:1       0.995191 -0.009849 0.097461 -95.062607                            sto_xyz:2       0.047470 0.918793 -0.391875 -52.154037                            sto_xyz:3       -0.085687 0.394617 0.914842 -189.548813                           sto_xyz:4       0.000000 0.000000 0.000000 1.000000 

Any clue?

Thank you,
Ramtin

@cookpa
Copy link
Member

cookpa commented Feb 8, 2024

Please post the full output of

PrintHeader ../defT1_bs.nii

as well as your OS and ANTs version.

@ramBrain
Copy link
Author

ramBrain commented Feb 8, 2024

The output of that line of code is as follows:

WARNING: In /usr/local/ANTs/build/ITKv5/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx, line 1934
NiftiImageIO (0x55875b149920): ../defT1_bs.nii has unexpected scales in sform
cant read ../defT1_bs.nii

OS is WSL under Windows 10 (Ubuntu 22.04.2 LTS)

ANTs version: 2.4.3.post23-g2d10611 (as reported in ANTsVersionConfig.h)

Many thanks,
Ramtin

@cookpa
Copy link
Member

cookpa commented Feb 8, 2024

Thanks. There were some ITK updates to try to avoid this problem. ITK requires an orthonormal cosine matrix, there can't be a shear or scaling (other than the voxel spacing). But sometimes it's too sensitive in detecting this.

Can you try the most recent ANTs? You can try binaries from the release page if you don't want to build from source again

@ramBrain
Copy link
Author

ramBrain commented Feb 8, 2024

Unfortunately the issue is still persistent. The difference with the previous prompt is that now it looks for ITKv5 in another folder, namely: /home/runner/work/_temp instead of /usr/local/ANTs

I cannot navigate to that directory though for some reason

@cookpa
Copy link
Member

cookpa commented Feb 8, 2024

OK, I'll have to look more into this and possibly involve the ITK folks. Can you share the problematic image? If not, can you share the header? You can do this with

head -c 352 image.nii > header.nii

Note you need to unzip first (it doesn't work with .nii.gz)

@ramBrain
Copy link
Author

ramBrain commented Feb 8, 2024

The problematic image is actually the default ICBM152 included in the Brainstorm toolbox, hence I can share it (attached).

I was wondering if I should install ITK separately? Or shall the binary files suffice to make ANTs work?

Many thanks
defT1_bs.zip

@cookpa
Copy link
Member

cookpa commented Feb 8, 2024

Perfect, you don't need to install ITK separately. The libraries are built into the executables. If you build from source, ITK will be downloaded and compiled first.

@gdevenyi
Copy link
Contributor

gdevenyi commented Feb 8, 2024

The problematic image is actually the default ICBM152 included in the Brainstorm toolbox, hence I can share it (attached).

I was wondering if I should install ITK separately? Or shall the binary files suffice to make ANTs work?

Many thanks defT1_bs.zip

The official MNI atlases are available in NIFTI form from the original authors, https://nist.mni.mcgill.ca/atlases/

@cookpa
Copy link
Member

cookpa commented Feb 8, 2024

It looks like this problem is caused by the header transform being almost orthonormal, but not quite enough for ITK. If you're OK with using the latest ANTs release, and dealing with some slight deviations in the image coordinates, you can set

export ITK_NIFTI_SFORM_PERMISSIVE=1

ITK will then "correct" the sform transform to be exactly orthonormal when reading the image. In this case:

 % fslhd defT1_bs.nii  | grep sto       
sto_xyz:1	0.969521 0.001320 -0.000507 -92.588768 
sto_xyz:2	-0.002264 0.970083 0.011989 -129.316452 
sto_xyz:3	0.003088 0.007503 0.991950 -78.728951 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
descrip		Written with Brainstorm

% PrintHeader defT1_bs.nii 2> /dev/null | grep srow         
    srow_x = 0.969521 0.00131987 -0.000507485 -92.5888
    srow_y = -0.00226438 0.970083 0.0119889 -129.316
    srow_z = 0.00308824 0.00750341 0.99195 -78.729

@cookpa
Copy link
Member

cookpa commented Feb 8, 2024

@ramBrain
Copy link
Author

ramBrain commented Feb 9, 2024

Many thanks for your help, I will try and see how it works.

Ramtin

@ramBrain ramBrain closed this as completed Feb 9, 2024
@ethanharvey98
Copy link

Any idea how to set

export ITK_NIFTI_SFORM_PERMISSIVE=1

in ANTsPy?

@cookpa
Copy link
Member

cookpa commented May 8, 2024

os.environ['ITK_NIFTI_SFORM_PERMISSIVE'] = '1'
import ants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants