ANTsX / ANTsR

R interface to the ANTs biomedical image processing library
https://antsx.github.io/ANTsR
Apache License 2.0
127 stars 35 forks source link

how to reorient image #280

Closed ptsii closed 4 years ago

ptsii commented 5 years ago

I have two images that appear to be facing in different directions (so to speak): They are not aligned properly so that I can register them together. I tried using reorientImage, but this gives me errors, and it isn't clear to me from the help how to use it. Here is what I tried:

brain_reorient<-reorientImage(brain,c(0,0,1))

However, I get:

/private/var/folders/mk/9_clkwx513df94kdv85c25m80000gn/T/RtmpJHQbPl/R.INSTALL8e9553218fbd/ITKR/src/itks/Modules/ThirdParty/VNL/src/vxl/core/vnl/algo/vnl_svd.hxx: suspicious return value (3) from SVDC /private/var/folders/mk/9_clkwx513df94kdv85c25m80000gn/T/RtmpJHQbPl/R.INSTALL8e9553218fbd/ITKR/src/itks/Modules/ThirdParty/VNL/src/vxl/core/vnl/algo/vnl_svd.hxx: M is 3x3 M = [ ... nan nan nan nan nan nan nan nan nan ]

Then when I try to plot it I get:

plot(brain_reorient) Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y'

From the help info, I also do not understand: axis1 vector of size dim, might need to play w/axis sign

If I wanted to flip a brain image around 180 degrees, so that the anterior pole is now pointing where the posterior pole was (and it isn't mirror imaged in any dimension), what parameters would I use? I assume it depends on where the anterior pole is pointing currently with respect to the x,y,z dimensions, but any clues to get me started would be appreciated.

-Tom

stnava commented 5 years ago

ReflectImage May do the job

On Tue, Sep 10, 2019 at 6:16 AM ptsii notifications@github.com wrote:

I have two images that appear to be facing in different directions (so to speak): They are not aligned properly so that I can register them together. I tried using reorientImage, but this gives me errors, and it isn't clear to me from the help how to use it. Here is what I tried:

brain_reorient<-reorientImage(brain,c(0,0,1))

However, I get:

/private/var/folders/mk/9_clkwx513df94kdv85c25m80000gn/T/RtmpJHQbPl/R.INSTALL8e9553218fbd/ITKR/src/itks/Modules/ThirdParty/VNL/src/vxl/core/vnl/algo/vnl_svd.hxx: suspicious return value (3) from SVDC /private/var/folders/mk/9_clkwx513df94kdv85c25m80000gn/T/RtmpJHQbPl/R.INSTALL8e9553218fbd/ITKR/src/itks/Modules/ThirdParty/VNL/src/vxl/core/vnl/algo/vnl_svd.hxx: M is 3x3 M = [ ... nan nan nan nan nan nan nan nan nan ]

Then when I try to plot it I get:

plot(brain_reorient) Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y'

From the help info, I also do not understand: axis1 vector of size dim, might need to play w/axis sign

If I wanted to flip a brain image around 180 degrees, so that the anterior pole is now pointing where the posterior pole was (and it isn't mirror imaged in any dimension), what parameters would I use? I assume it depends on where the anterior pole is pointing currently with respect to the x,y,z dimensions, but any clues to get me started would be appreciated.

-Tom

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTsR/issues/280?email_source=notifications&email_token=AACPE7TNQA7OUZDXV4FBZILQI5XZJA5CNFSM4IVFXWVKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HKM6BXQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AACPE7RMON3FFJYCXHJBWHDQI5XZJANCNFSM4IVFXWVA .

--

brian

ptsii commented 4 years ago

In case anyone finds it helpful in the future, I think I found a good way to reorient images, using ANTs, ITKSNAP, and c3d (part of ITKSNAP):

1) use the c3d -trim option to center each object into its own image space, and pad to some value (e.g., 40)

2) use ITKSNAP to add corresponding points to a binary of the object (each point having a different label value). I found it useful to 3D render the binary object, and then use the tools to place points

3) use ANTs antsLandmarkBasedTransformInitializer to find a rigid mapping between the pair of images with ITKSNAP-added corresponding points, e.g.,:

antsLandmarkBasedTransformInitializer 3 target_image_with_ITKSNAP_points.nii.gz image_to_be_rotated_with_ITKSNAP_points.nii.gz rigid image_to_rotate_to_target_image_transform.mat

4) apply the transform to create the new aligned version of the image_to_be_rotated (using ANTs antsApplyTransforms):

antsApplyTransforms -d 3 -i image_to_be_rotated_without_ITKSNAP_points.nii.gz -r target_image_without_ITKSNAP_points.nii.gz -o image_to_be_rotated_in_target_image_space.nii.gz -n NearestNeighbor -t image_to_rotate_to_target_image_transform.mat

stnava commented 4 years ago

Other more direct options exist but this is fine.