I'd like to convert the warp field NIFTI image output by AntsRegistration to .mat format so I can apply it to a list of coordinates using antsApplyTransformsToPoints. Is this possible? If so which executable does the trick?
Thanks for your help,
-Zack
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There's no need for that . you should use antsapplytransformstopoints
directly.
On Jul 1, 2015 5:04 PM, "Zachary Greenberg" zackg61@users.sf.net wrote:
Hi,
I'd like to convert the warp field NIFTI image output by AntsRegistration
to .mat format so I can apply it to a list of coordinates using
antsApplyTransformsToPoints. Is this possible? If so which executable does
the trick?
I'm having a hard time following. Perhaps there's a couple of incorrect assumptions. A .mat file is used to store the linear transforms whereas the nifti images are used to store the displacement fields. Both file types are readable by antsApplyTransformsToPoints.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Inverse does not exist for brain_InverseWarp.nii.gz
Segmentation fault (core dumped)
I was assuming from the instructions in the help, that we treat the transform the same way we would when trying to apply the affine from a .mat file (i.e., give it the inverse of the transform you want to apply). Am I mistaken there? or is there possibly something else going wrong?
-zack
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Inverse does not exist for brain_InverseWarp.nii.gz
Segmentation fault (core dumped)
I was assuming from the instructions in the help, that we treat the
transform the same way we would when trying to apply the affine from a .mat
file (i.e., give it the inverse of the transform you want to apply). Am I
mistaken there? or is there possibly something else going wrong?
Inverse does not exist for fs_data/mri/brain_RAIdeformed.nii.gz
Segmentation fault (core dumped)
Without the inverse flag, it runs successfully, but produces a very strange result (see attached image).
Thanks!
Matt
EDIT: Sorry, I should also mention that I've tried using a variety of the non-linear transformations, including brain_RAIWarp.nii.gz. Still doesn't work with the inverse flag, and gives results that don't make sense without the flag.
The inverse flag only works for linear transforms for which the inverse transform is easily calculated within antsApplyTransforms. The inverse field is not calculated for displacement field transforms on the fly within antsApplyTransforms. Presumably, if you calculated the forward transform using one of the invertible transform types in antsRegistration then you'd be able to specify the inverse transform directly, i.e. antsApplyTransforms ... -t fs_data/mri/brain_RAIdeformedInverse.nii.gz.
(In responding to this example, I'm assuming that the file fs_data/mri/brain_RAIdeformed.nii.gz is actually a warp field although it doesn't conform to ANTs naming conventions.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So does it make sense to apply the deformed.nii.gz warp field to a set of points? When I actually view the nii volume, it looks a lot like the template I'm trying to warp to, but maybe I'm just not clear on how to apply the transform to a set of voxel coordinates in the original volume.
I appreciate your help answering this question.
Matt
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So does it make sense to apply the deformed.nii.gz warp field to a set of
points? When I actually view the nii volume, it looks a lot like the
template I'm trying to warp to, but maybe I'm just not clear on how to
apply the transform to a set of voxel coordinates in the original volume.
I had stepped through the chicken example, and got it to work with the affine transform, but I'm having trouble applying the SyN warp to my actual points.
I just tried a test where I selected a single point in the original volume and tried to apply the various combinations of the affine and warp to that point.
The end result is that regardless of parameters (inverse, affine vs. no affine, etc), it does not appear that antsApplyTransformsToPoints does anything to the single point with the warp. It does an affine transform if I apply it, but the coordinates of the point are identical with the warp vs. no warp.
I've checked that the warp field works for the volume using antsApplyTransforms, and the warp field itself actually has data in it, so my question is how to use that warp on points.
We are using LPS coordinates in the volume space, so that shouldn't be a problem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
if that is the case, then you are making some mistake.
since you already read the chicken example, i've updated it further to use
deformable mapping along with affine. keep in mind that, in the world of
ITK and ANTs, the same code is used to transform points as is used for
images. so if you can map images, you can map points.
I had stepped through the chicken example, and got it to work with the
affine transform, but I'm having trouble applying the SyN warp to my actual
points.
I just tried a test where I selected a single point in the original volume
and tried to apply the various combinations of the affine and warp to that
point.
The end result is that regardless of parameters (inverse, affine vs. no
affine, etc), it does not appear that antsApplyTransformsToPoints does
anything to the single point with the warp. It does an affine transform if
I apply it, but the coordinates of the point are identical with the warp
vs. no warp.
I've checked that the warp field works for the volume using
antsApplyTransforms, and the warp field itself actually has data in it, so
my question is how to use that warp on points.
We are using LPS coordinates in the volume space, so that shouldn't be a
problem.
ok, another question: I've almost got this working but I'm running into the issue of mapping between LPS coordinates, and the LPS coordinates that ANTS is expecting...
So I know that in Slicer's LPS coordinates one of my voxels is
73.00000953, 157.0000032 , 150.99999258
and using ANTs imagemath and labelstats on a volume with that coordinate as a 1, I can see that ANTs thinks this coordinate is
50.8625,-12.7275,-12.8785
another example pair
Slicer LPS
75.00000941, 157.00000326, 154.99999259
ANTs LPS
48.8625,-12.7275,-16.878
So I tried applying the difference between the first pair to all coordinates in my Slicer LPS matrix, but I don't think that is representing scaling correctly (i.e., there's a different Slicer LPS-ANTS LPS difference between the two pairs above).
So my question is: how do I correctly extract the transformation (translation, rotation, and scaling) from my Slicer LPS coordinates to the LPS ANTS is expecting?
Let me know if this is not making sense.
Thanks for your help.
-zack
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ok, another question: I've almost got this working but I'm running into
the issue of mapping between LPS coordinates, and the LPS coordinates that
ANTS is expecting...
So I know that in Slicer's LPS coordinates one of my voxels is
73.00000953, 157.0000032 , 150.99999258
and using ANTs imagemath and labelstats on a volume with that coordinate
as a 1, I can see that ANTs thinks this coordinate is
50.8625,-12.7275,-12.8785
another example pair
Slicer LPS
75.00000941, 157.00000326, 154.99999259
ANTs LPS
48.8625,-12.7275,-16.878
So I tried applying the difference between the first pair to all
coordinates in my Slicer LPS matrix, but I don't think that is representing
scaling correctly (i.e., there's a different Slicer LPS-ANTS LPS difference
between the two pairs above).
So my question is: how do I correctly extract the transformation
(translation, rotation, and scaling) from my Slicer LPS coordinates to the
LPS ANTS is expecting?
Let me know if this is not making sense.
Thanks for your help.
-zack
Hi,
I'd like to convert the warp field NIFTI image output by AntsRegistration to .mat format so I can apply it to a list of coordinates using antsApplyTransformsToPoints. Is this possible? If so which executable does the trick?
Thanks for your help,
-Zack
There's no need for that . you should use antsapplytransformstopoints
directly.
On Jul 1, 2015 5:04 PM, "Zachary Greenberg" zackg61@users.sf.net wrote:
I'm having a hard time following. Perhaps there's a couple of incorrect assumptions. A .mat file is used to store the linear transforms whereas the nifti images are used to store the displacement fields. Both file types are readable by antsApplyTransformsToPoints.
Ok, I tried applying the warp field from the output nifti volume and received the following error:
$ANTSPATH/antsApplyTransformsToPoints -d 3 -i /path/to/points.csv -o points_warped.csv -t [/path/to/brain_InverseWarp.nii.gz, 1]
Inverse does not exist for brain_InverseWarp.nii.gz
Segmentation fault (core dumped)
I was assuming from the instructions in the help, that we treat the transform the same way we would when trying to apply the affine from a .mat file (i.e., give it the inverse of the transform you want to apply). Am I mistaken there? or is there possibly something else going wrong?
-zack
You should not try to invert the inverse.
On Jul 2, 2015 4:50 PM, "Zachary Greenberg" zackg61@users.sf.net wrote:
I seem to be having the same issue, except I'm not using the InverseWarp:
$ANTSPATH/antsApplyTransformsToPoints -d 3 -i elecs/hd_grid.csv -o elecs/hd_grid_warped.csv -t [fs_data/mri/brain_RAIdeformed.nii.gz ,1]
Inverse does not exist for fs_data/mri/brain_RAIdeformed.nii.gz
Segmentation fault (core dumped)
Without the inverse flag, it runs successfully, but produces a very strange result (see attached image).
Thanks!
Matt
EDIT: Sorry, I should also mention that I've tried using a variety of the non-linear transformations, including brain_RAIWarp.nii.gz. Still doesn't work with the inverse flag, and gives results that don't make sense without the flag.
Last edit: Matt Leonard 2015-08-13
The inverse flag only works for linear transforms for which the inverse transform is easily calculated within
antsApplyTransforms
. The inverse field is not calculated for displacement field transforms on the fly withinantsApplyTransforms
. Presumably, if you calculated the forward transform using one of the invertible transform types inantsRegistration
then you'd be able to specify the inverse transform directly, i.e.antsApplyTransforms ... -t fs_data/mri/brain_RAIdeformedInverse.nii.gz
.(In responding to this example, I'm assuming that the file
fs_data/mri/brain_RAIdeformed.nii.gz
is actually a warp field although it doesn't conform to ANTs naming conventions.)OK, I see, that makes sense.
So does it make sense to apply the deformed.nii.gz warp field to a set of points? When I actually view the nii volume, it looks a lot like the template I'm trying to warp to, but maybe I'm just not clear on how to apply the transform to a set of voxel coordinates in the original volume.
I appreciate your help answering this question.
Matt
the chicken example previously referenced tries to make it clear.
any suggestions on improving it would be welcome.
but what i usually find in answering this type of question is that the
example often goes unread.
basically, to warp points, you use the inverse of the transformations
that you would apply to images.
but you have to define the points in the ITK image space for this to work
correctly.
if your selected transformation model does not have an inverse (e.g.
elastic) then you can't apply it to points. at least not with ants.
brian
On Thu, Aug 13, 2015 at 5:53 PM, Matt Leonard mkleonard@users.sf.net
wrote:
I had stepped through the chicken example, and got it to work with the affine transform, but I'm having trouble applying the SyN warp to my actual points.
I just tried a test where I selected a single point in the original volume and tried to apply the various combinations of the affine and warp to that point.
The end result is that regardless of parameters (inverse, affine vs. no affine, etc), it does not appear that antsApplyTransformsToPoints does anything to the single point with the warp. It does an affine transform if I apply it, but the coordinates of the point are identical with the warp vs. no warp.
I've checked that the warp field works for the volume using antsApplyTransforms, and the warp field itself actually has data in it, so my question is how to use that warp on points.
We are using LPS coordinates in the volume space, so that shouldn't be a problem.
if that is the case, then you are making some mistake.
since you already read the chicken example, i've updated it further to use
deformable mapping along with affine. keep in mind that, in the world of
ITK and ANTs, the same code is used to transform points as is used for
images. so if you can map images, you can map points.
see:
https://github.com/stnava/chicken/commit/bcbddd83c67b5728e29112cda20ff2fd512ad0b6
brian
On Mon, Aug 17, 2015 at 2:29 PM, Matt Leonard mkleonard@users.sf.net
wrote:
ok, another question: I've almost got this working but I'm running into the issue of mapping between LPS coordinates, and the LPS coordinates that ANTS is expecting...
So I know that in Slicer's LPS coordinates one of my voxels is
73.00000953, 157.0000032 , 150.99999258
and using ANTs imagemath and labelstats on a volume with that coordinate as a 1, I can see that ANTs thinks this coordinate is
50.8625,-12.7275,-12.8785
another example pair
Slicer LPS
75.00000941, 157.00000326, 154.99999259
ANTs LPS
48.8625,-12.7275,-16.878
So I tried applying the difference between the first pair to all coordinates in my Slicer LPS matrix, but I don't think that is representing scaling correctly (i.e., there's a different Slicer LPS-ANTS LPS difference between the two pairs above).
So my question is: how do I correctly extract the transformation (translation, rotation, and scaling) from my Slicer LPS coordinates to the LPS ANTS is expecting?
Let me know if this is not making sense.
Thanks for your help.
-zack
lots of discussion of this type of thing on source forge discussion site.
also, see: https://github.com/stnava/chicken
use snap to define landmarks etc.
brian
On Mon, Jul 20, 2015 at 4:15 PM, Zachary Greenberg zackg61@users.sf.net
wrote: