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

ANTs and antsRegistration produce different qform orientations #873

Closed
moskvich412 opened this issue Oct 10, 2019 · 18 comments
Closed

ANTs and antsRegistration produce different qform orientations #873

moskvich412 opened this issue Oct 10, 2019 · 18 comments

Comments

@moskvich412
Copy link

ANTs and antsRegistration produce wrap fields with different q-forms:

ANTs:
qform_xorient Right-to-Left
qform_yorient Posterior-to-Anterior
qform_zorient Inferior-to-Superior

antsRegistration:
qform_xorient Right-to-Left
qform_yorient Anterior-to-Posterior
qform_zorient Inferior-to-Superior

One is left the other is right handed (y-orient is swapped). If it is not used, it is irrelevant and this is not a bug. But is it used by antsApplyTransforms?

@gdevenyi
Copy link
Contributor

Can you please provide a complete reproducible example (with data).

@ntustison
Copy link
Member

Did you read this?

Regardless, antsApplyTransforms should work with either ANTS or antsRegistration output.

@moskvich412
Copy link
Author

I did more testing. I use antsRegistrationSyNQuick.sh. When moving and fixed images are two-time point NIFTI files ( I had T1W imaged glued to its FreeSurfer segmentation), then qform of the output Warp.nii (deformation field) is

qform_yorient Anterior-to-Posterior.

When I supply single time point (T1W itself), the qform of the warp is

qform_yorient Posterior-to-Anterior

I was always supplying single time point to ANTs and thus the discrepancy. Is qform of the warp field meaningful (used somewhere)? From description y=x + u(x) it should not.

Is it expected that behavior should change with the number of time points? Are they both used in the search?

@cookpa
Copy link
Member

cookpa commented Oct 11, 2019 via email

@moskvich412
Copy link
Author

The -d argument puzzles me in general. NIFTI header has this information.

So, if this is not a bug, this issue should be closed. At the same time, perhaps something should force consistency between -d and NIFTI header or produce error on mismatch since conflicting information is being supplied.,

@ntustison
Copy link
Member

We've actually been working on this software for quite some time and, as a result, it has been vetted by us and many users over that same period of time. So perhaps instead of assuming or questioning if certain behavior constitutes a bug, it would probably be more helpful (and respectful) if you, instead, ask why things are a certain way.

Although the Nifti header contains that information, at times it's useful to force the program to read things as having a specific dimension which is why that option is in most, if not all, of ANTs programs.

@ntustison
Copy link
Member

In addition, it simplifies the IO situation in ANTs where we're handling multiple image formats and not just Nifti.

@moskvich412
Copy link
Author

I did not assume it is a bug. To quote my first post: "If it is not used [in reference to qform of warp fields], it is irrelevant and this is not a bug. But is it used by antsApplyTransforms?" In the last post, I wrote: " if this is not a bug, this issue should be closed". I did not assume. I asked. Respectfully.

And I read before hand how qform is used and sform is not in the ANTs manual. The manual does not mention how qform is used in the warp field file. Only in moving and fixed images. But seeing different qforms from what seemed to me should produce identical results I searched the web. Not finding anything, I asked. Is it a bug? Is qform used?

I need this qform to be valid for what I am doing. And precisely because I knew people worked and tested this many times, I had to understand why it changes. Cookpa helpfully provided link to issue 250, which is similar but not identical. Thus, I am not the only one puzzled, if puzzled is something that was interpreted as disrespect.

I still do not know reasoning behind change of qform. But I know it is not a bug. If someone can explain or provide link, I promise I will read. Otherwise, I will be careful to watch how many time points I supply knowing that it will work right without knowing the reason.

@gdevenyi
Copy link
Contributor

Can you please provide a complete reproducible example (with data).

@cookpa
Copy link
Member

cookpa commented Oct 11, 2019

@gdevenyi you can do it by switching in a 4D reference image while calling antsApplyTransforms with -d 3, as in the example here.

#250

@moskvich412
Copy link
Author

I definitely can provide complete example. But this does not seem to be a bug. A bug is when a routine behaves not as intended. I can only determine if routine behaves not as I expect. I can not determine if this is a bug. Only developers can. Nick seems to indicate that this is not a bug and is indeed intended behavior. Then, no more effort should be spent. But if providing example data and command is nevertheless useful in some way, I will. Please let me know.

@cookpa
Copy link
Member

cookpa commented Oct 11, 2019

I still do not know reasoning behind change of qform. But I know it is not a bug. If someone can explain or provide link, I promise I will read. Otherwise, I will be careful to watch how many time points I supply knowing that it will work right without knowing the reason.

I think it's related to the reason for the -d flag, or at least one of the reasons, which is templating. The code is written once, templated over the ImageDimension that you specify with -d. At run time, the expected dimensions are attached to each object. When you run antsApplyTransforms -d 3, the program sets up an object that works in 3D. It does this before any of the images are read in.

This same idea is also in the ITK code. The ITK filter for reading an image is the same for all dimensions, so it has a single routine for dealing with the case that the input image has more dimensions than expected, which has to be consistent over all dimensions and file types. And they decided that for reading D dimensions from a (D+i)-dimension image, to just read the first D dimensions of the (D+i) voxel grid. But they do not attempt to figure out the physical space transform, instead setting it to ITK's default. This is the reason that your qforms are different.

From the ANTs code perspective, we pass a file name and ask for a D-dimensional image, and the ITK filter returns a D-dimensional image. It doesn't tell us if it subsetted that image out of a (D+i) image. So there's not much we can do about this unless someone gets a pull request approved for ITK to do things differently.

@moskvich412
Copy link
Author

Thank you, cookpa, for explanation. As understood, if there is mismatch between requested (via -d D ) and actual (file header D+/- i ) dimensions, ITK uses default orientation for the requested D. ITK does not inform when such substitution took place. But there is only one -d for all the images. If fixed and moving (and reference for antsApplyTransform) images have different dimensions, then all calculations will be based on incorrect orientations. That is why there is -e 3 for time series, which effectively means "use -d 4 for the moving image". This also explains a problem I had with -e 3, which produced incorrect output. I used NIFTI with 2 time points as reference.

@cookpa
Copy link
Member

cookpa commented Oct 11, 2019

Yes -d should match the same argument in antsRegistration, and the reference image should also have the same dimensionality. -d 4 means do / apply a 4D registration, with 4D warps. -d 3 and -e 2 means apply a 3D warp to each volume of a 4D time series

@moskvich412
Copy link
Author

If NIFTI with single time point (not a 5D, not a vector in 3D) is passed as warp to antsApplyTransform, then antsApplyTransform still succeeds (exit code is 0) with nonsense output. I understand the root of the problem is ITK. Despite ITK noticed discrepancy, a user must duplicate the code (on scripting level) to detect such input errors.

@moskvich412
Copy link
Author

Well.. same applies to corrupt files. I truncated moving NIFTI image (this can happen if a previous process is killed while writing a file to disk) and antsApplyTransform did not complain (exit code 0).

@cookpa
Copy link
Member

cookpa commented Oct 14, 2019

I'll make a note of this on the wiki, but it's unlikely we could fix this as the information is not exposed by the ITK filter we use to read the (many) different file types.

@cookpa
Copy link
Member

cookpa commented Oct 15, 2019

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