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

Refactor antsTransformInfo to add some error handling and compute determinant #1712

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

gdevenyi
Copy link
Contributor

@gdevenyi gdevenyi commented Apr 2, 2024

I'd like to be able to easily extract the determinant of affine transforms and antsTransformInfo seems like the right place.

The function has been refactored to handle reading errors.

Based primarily off
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Examples/IO/TransformReadWrite.cxx

Things that aren't done:

  • I don't know how to automatically handle the 2D vs 3D transforms. The previous simple read/print code didn't seem to need it whereas this version does.

@cookpa
Copy link
Member

cookpa commented Apr 2, 2024

Once the transform is read, I think you can call GetInputSpaceDimension() on it to determine the dimensionality

@cookpa
Copy link
Member

cookpa commented Apr 2, 2024

The program as written is not restricted to affine transforms, it will read any supported transform file. Assuming affine transforms would actually restrict its functionality.

Maybe the determinant computation would be better added to iMath or something?

@gdevenyi
Copy link
Contributor Author

gdevenyi commented Apr 2, 2024

The program as written is not restricted to affine transforms,

Can you give an example? I tried this on Warpfields and it falls over, I don't know of any other transform types which couldn't be cast to an affine...

@cookpa
Copy link
Member

cookpa commented Apr 2, 2024

If you run antsRegistration with --output-composite-transform, it will read the resulting transform file.

@gdevenyi
Copy link
Contributor Author

gdevenyi commented Apr 2, 2024

Got it.

Looks like I need to read all transforms as composite transforms and then figure out how to unpack it back into a list and loop over the unpacked components, checking the type.

@cookpa
Copy link
Member

cookpa commented Apr 17, 2024

From the discourse, seems like dynamic casting to MatrixOffsetTransformBase would be sufficient. If that's not null, you can call GetMatrix() on the result

@gdevenyi
Copy link
Contributor Author

@gdevenyi gdevenyi force-pushed the enhance-antsTransformInfo branch 3 times, most recently from b8e9b5d to 9d1a989 Compare May 30, 2024 16:10
@gdevenyi gdevenyi marked this pull request as ready for review May 30, 2024 17:22
@gdevenyi
Copy link
Contributor Author

This now will unpack transform lists as well as CompositeTransforms and print the determinant in addition to the PrintSelf for every transform in the whole stack.

@cookpa
Copy link
Member

cookpa commented May 30, 2024

Thanks - I'm going to be out of the office, so might be some time before I get to this

@gdevenyi
Copy link
Contributor Author

Context of this work is I use affine determinants in steps of
https://github.com/CoBrALab/optimized_antsMultivariateTemplateConstruction

And currently I have to do this by using antsApplyTransforms to produce a warp field from the affine and then a Jacobian file from that. This will allow me to just compute the the jacobian determinant with antsTransformInfo and extract it from the text output.

@cookpa
Copy link
Member

cookpa commented Jun 12, 2024

I didn't verify the determinant values but it appears to work with the supported transform types

@cookpa
Copy link
Member

cookpa commented Jun 12, 2024

Thanks for this @gdevenyi

@cookpa cookpa merged commit ca4af10 into ANTsX:master Jun 12, 2024
1 check passed
@gdevenyi
Copy link
Contributor Author

I have tested the output values using MINC affine transforms, where the I can generate arbitrary transforms with param2xfm (giving a known determinant) and then compute the determinant using both MINC tools and antsTransformInfo 👍

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

Successfully merging this pull request may close these issues.

2 participants