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

antsApplyTransforms #340

Open
marivas-MRI opened this issue Feb 12, 2021 · 4 comments
Open

antsApplyTransforms #340

marivas-MRI opened this issue Feb 12, 2021 · 4 comments

Comments

@marivas-MRI
Copy link

Hi,

I have two images (A.nii, B.nii). After perform SyN registration from A.nii to B.nii, I obtained the C0GenericAffine.mat, C1InverseWarp.nii.gz and the C1Warp.nii.gz files.

Now my goal is to apply the registration fields obtained in registration A.nii ---> B.nii to the A.nii image. For that purpose I am trying to use the antsApplyTransforms using this command:

antsApplyTransforms ('B.nii', 'A.nii', transformlist = "C0GenericAffine.mat", interpolator = 'nearestNeighbor', imagetype = 0, whichtoinvert = FALSE, compose = NA, verbose = FALSE)

and the output is

[1] 1

I am very new using ANTsR tools, can anyone suggest to me the correct command to apply the deformation fields to the A.nii image??

Thanks for your help.

Best regards,

@stnava
Copy link
Member

stnava commented Feb 12, 2021

see ?antsApplyTransforms

@marivas-MRI
Copy link
Author

Before asking I have tried to follow the instructions and again I have not been able to do it correctly. Could you help me please?

Thank you and excuse me for this kind of questions.

Best,

@ntustison
Copy link
Member

If you type ?antsApplyTransforms, you'll see an example that you should try to reproduce before asking about your specific example.

@ptsii
Copy link

ptsii commented Mar 12, 2021

Here's what I do:

First the registration:

ImageA_into_ImageB_reg<-antsRegistration(ImageB, ImageA, typeofTransform = "SyNRA")

First, note that the resulting object: ImageA_into_ImageB_reg itself CONTAINS ImageA transformed into ImageB already. If you enter the name of this object by itself on R's commandline, you get something like:

> ImageA_into_ImageB_reg

$warpedmovout
antsImage
  Pixel Type          : float 
  Components Per Pixel: 1 
  Dimensions          : 218x209x255 
  Voxel Spacing       : 0.75x0.75x0.75 
  Origin              : 6.75 6.75 -3.75 
  Direction           : -1 0 0 0 -1 0 0 0 1 


$warpedfixout
antsImage
  Pixel Type          : float 
  Components Per Pixel: 1 
  Dimensions          : 218x209x255 
  Voxel Spacing       : 0.75x0.75x0.75 
  Origin              : 6.75 6.75 -3.75 
  Direction           : -1 0 0 0 -1 0 0 0 1 


$fwdtransforms
[1] "/var/folders/mk/9_clkwx513df94kdv85c25m80000gn/T//RtmpV5JKx3/file8134589d25581Warp.nii.gz"      
[2] "/var/folders/mk/9_clkwx513df94kdv85c25m80000gn/T//RtmpV5JKx3/file8134589d25580GenericAffine.mat"

$invtransforms
[1] "/var/folders/mk/9_clkwx513df94kdv85c25m80000gn/T//RtmpV5JKx3/file8134589d25580GenericAffine.mat" 
[2] "/var/folders/mk/9_clkwx513df94kdv85c25m80000gn/T//RtmpV5JKx3/file8134589d25581InverseWarp.nii.gz"

$prev_transforms
character(0)

In other words, ImageA_into_ImageB_reg$warpedmovout is (in this case) ImageA warped into ImageB. You can check this by doing:

plot(ImageA_into_ImageB_reg$warpedmovout)

(Similarly ImageA_into_ImageB_reg$warpedfixout is ImageB warped into ImageA)

However, these are created using (I believe) linear interpolation. If you want to use a different kind of interpretation, you'd use antsApplyTransforms, and specify a particular type of interpolation. For example:

ImageA_in_ImageB_nearestNeighbor_interpolation_image<-antsApplyTransforms(ImageB, ImageA, transformlist = ImageA_into_ImageB_reg$fwdtransforms, interpolator = "nearestNeighbor")
This would apply nearest-neighbor interpolation to the transform.

I believe this is correct...

-Tom

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