muschellij2 / extrantsr

R Package to build on ANTsR
GNU General Public License v3.0
6 stars 3 forks source link

support different interpolations with the same registration? #3

Closed Tazinho closed 7 years ago

Tazinho commented 7 years ago

At the moment I am using ants_regwrite() to register different niftis on a template. The niftis differ in their scales. I have binary and metrical maps. So I need different interpolation arguments and so I need to call ants_regwrite() two times. My main issue with this, is that this means that the registration is done two times, which (as I understand) leads to (minimal) different transformations (since there seems to be now way to control external random number generators) and doubled runtime.

Is there a compact highlevel syntax invoking ants_regwrite() or similar to do sth like the following, just with using two times the same transformation?

ants_regwrite(filename = some_file_path,
              outfile = some_file_output_path,
              other.files = other_metrical_file_paths,
              other.outfiles = other_metrical_file_output_paths,
              template.file = some_template_path
              interpolator = "linear")

ants_regwrite(filename = some_file_path,
              outfile = some_file_output_path,
              other.files = other_binary_file_paths,
              ther.outfiles = other_binary_file_output_paths,
              template.file = some_template_path
              interpolator = "nearestNeighbor")
muschellij2 commented 7 years ago

I would use the registration function, which has some different defaults, but is a better registration wrapper, and returns a list of the transformations and the files.

reg = registration(filename = some_file_path,
              outfile = some_file_output_path,
              other.files = other_metrical_file_paths,
              other.outfiles = other_metrical_file_output_paths,
              template.file = some_template_path,
              interpolator = "linear")
res = ants_apply_transforms(fixed = template.file, 
moving = other_binary_file_paths, transformlist = reg$fwdtransforms, 
interpolator = "nearestNeighbor")
mapply(function(img, fname) {
    writenii(img, fname)
}, res, other_binary_file_output_paths)

These functions wrap antsApplyTransforms and antsRegistration from ANTsR

Tazinho commented 7 years ago

Thanks for your quick response! This sounds really good. For everyone with the same usecase:

ants_apply_transforms() 
Error in antsApplyTransforms(fixed = fixed, moving = moving, transformlist = transformlist,  : 
  Transform /tmp/RtmpzANGJs/file161b39a9966c1Warp.nii.gz does not exist.

These should be found in:

> reg$fwdtransforms
[1] "/tmp/RtmpzANGJs/file161b39a9966c1Warp.nii.gz"      
[2] "/tmp/RtmpzANGJs/file161b39a9966c0GenericAffine.mat"

But are only, if you made the setting above.