jonclayden/RNiftyReg

RNiftyrReg load in previously generated nonlinear transfrom

CST333 opened this issue · 6 comments

Dear all,

I would like to apply nonlinear transformations to landmarks (e.g. stored in a csv file). My transformations are already created using the commandline (reg_f3d), so I would like to load them into R and use ApplyTransforms, how do I do that?

thanks!
C.

Hi! If you have a control point image from reg_f3d, and the associated source (floating) and target (reference) images, you should be able to read it into R with something like

library(RNiftyReg)
xfm <- readNifti("control_points.nii", source="source.nii", target="target.nii")

You should be able to read your landmarks in with

points <- as.matrix(read.csv("landmarks.csv"))

and then transform them with

applyTransform(xfm, points)

I hope that helps.

Hi, Thank you for your help.
I have the control points (CPP file), but when I want to read them in like you suggest

xfm <- readNifti("control_points.nii", source="source.nii", target="target.nii")

there is an error " unused arguemtns (..) source = (...), target = (..)"
and then the applyTransfrom gives an error " Object to transform should be a suitable image or matrix of points." My csv file has x,y,z coordinates and it looks okay.

I also tried to apply the transfrom to the source image:

transform <- readNifti("transfrom_CPP.nii.gz", source="source.nii.gz", target="target.nii.gz") source <- readNiftii("source.nii.gz") applyTransfrom(transform, source)

and it gives me the same errors. Do you have any idea, what I am doing wrong?
best, C.

Are you able to share the files you're working with?

I can't share the subjects, but I rerun the code on two templates (register template 32 weeks to template 44 weeks) just to recreate a similar output.

Here is what I did in the terminal to get the CPP:
reg_f3d -ref T2_44.nii.gz -flo 32_to_44_aligned.nii.gz -aff 32_to_44_alignment.txt -res 32_to_44_deformed.nii.gz -cpp 32_to_44_deformation.nii.gz -sx -5 -sy -5 -sz -5 -be 0.05

when I try to read in in R using:
transform <- readNifti("32_to_44_deformation.nii.gz", source="32_to_44_aligned.nii.gz", target="T2_44.nii.gz")

I get the same error:
"Error in readNifti("32_to_44_deformation.nii.gz", :
unused arguments (source = "...", target = "...")

and when I try to apply the Transform to the source image
source <- readNifti("32_to_44_aligned.nii.gz") applyTransform(transform, source)

I get "Object to transform should be a suitable image or matrix of points."

32_to_44_aligned.nii.gz
32_to_44_alignment.txt
32_to_44_deformation.nii.gz
32_to_44_deformed.nii.gz
T2_44.nii.gz

I can't reproduce the problem:

library(RNiftyReg)
transform <- readNifti("32_to_44_deformation.nii.gz", source="32_to_44_aligned.nii.gz", target="T2_44.nii.gz")
source <- readNifti("32_to_44_aligned.nii.gz")
applyTransform(transform, source)
## Image array of mode "double" (17.9 Mb)
## - 117 x 159 x 126 voxels
## - 0.8594 x 0.8594 x 0.8594 mm per voxel

Is RNiftyReg up-to-date? Do you have other packages loaded that are masking its namespace? Are you doing other steps that you haven't listed?

I restarted R and loaded RNiftyReg [Package RNiftyReg version 2.7.0] and now it works. I think I had a module loaded without knowing - thank you for your help!