ANTsX / ANTs

Advanced Normalization Tools (ANTs)
Apache License 2.0
1.21k stars 381 forks source link

Dimensionality / components of Nonlinear Warp Images #1314

Closed nicolatoschi closed 2 years ago

nicolatoschi commented 2 years ago

Dear Developers,

a "hopefully" quick question about the format in whcih nonlinear warps are outputted by ANTs.

I was expecting each warp image to have dimensions Nx Ny Nz 3, where the first three are teh size of fixed image and the fourth dimension would be the components of the local warp vector. Instead, the warp images are scalar images.

Could you please explain this format and, if possible, guide me in extracting the warp components?

Thank you in advance,

Nicola Toschi

ntustison commented 2 years ago

Self-contained 2-D example which you should be able to extrapolate to 3-D:

Python 3.7.6 (default, Jan  8 2020, 13:42:34) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ants
>>> r16 = ants.image_read(ants.get_ants_data("r16"))
>>> r64 = ants.image_read(ants.get_ants_data("r64"))
>>> reg = ants.registration(r16, r64, type_of_transform="antsRegistrationSyNQuick[so]")
>>> displacement_field = ants.image_read(reg['fwdtransforms'][0])
>>> displacement_field.shape
(256, 256)
>>> displacement_field
ANTsImage
     Pixel Type : float (float32)
     Components : 2
     Dimensions : (256, 256)
     Spacing    : (1.0, 1.0)
     Origin     : (0.0, 0.0)
     Direction  : [1. 0. 0. 1.]

>>> displacement_field_components = ants.split_channels(displacement_field)
>>> displacement_field_components
[ANTsImage
     Pixel Type : float (float32)
     Components : 1
     Dimensions : (256, 256)
     Spacing    : (1.0, 1.0)
     Origin     : (0.0, 0.0)
     Direction  : [1. 0. 0. 1.]
, ANTsImage
     Pixel Type : float (float32)
     Components : 1
     Dimensions : (256, 256)
     Spacing    : (1.0, 1.0)
     Origin     : (0.0, 0.0)
     Direction  : [1. 0. 0. 1.]
]
>>> 
nicolatoschi commented 2 years ago

Thank you so much.

At the moment I am simply working with the executables, i.e. with the .nii.gz Warp and Inversewarp images produced by antsRegistration.

Is there a bash executable equivalent to ants.split_channels in your python script?

Thank you again,

Nicola

On 3/7/2022 1:05 AM, Nick Tustison wrote:

Self-contained 2-D example which you should be able to extrapolate to 3-D:

|Python 3.7.6 (default, Jan 8 2020, 13:42:34) [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import ants >>> r16 = ants.image_read(ants.get_ants_data("r16")) >>> r64 = ants.image_read(ants.get_ants_data("r64")) >>> reg = ants.registration(r16, r64, type_of_transform="antsRegistrationSyNQuick[so]") >>> displacement_field = ants.image_read(reg['fwdtransforms'][0]) >>> displacement_field.shape (256, 256) >>> displacement_field ANTsImage Pixel Type : float (float32) Components : 2 Dimensions : (256, 256) Spacing : (1.0, 1.0) Origin : (0.0, 0.0) Direction : [1. 0. 0. 1.] >>> displacement_field_components = ants.split_channels(displacement_field) >>> displacement_field_components [ANTsImage Pixel Type : float (float32) Components : 1 Dimensions : (256, 256) Spacing : (1.0, 1.0) Origin : (0.0, 0.0) Direction : [1. 0. 0. 1.] , ANTsImage Pixel Type : float (float32) Components : 1 Dimensions : (256, 256) Spacing : (1.0, 1.0) Origin : (0.0, 0.0) Direction : [1. 0. 0. 1.] ] >>> |

— Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTs/issues/1314#issuecomment-1060070117, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFE4XAYYEQSB2OBANFQHMDU6VB55ANCNFSM5QBY5NOA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Web Bug from https://github.com/notifications/beacon/AOFE4XHKJ5TWG632X4TT6ZTU6VB55A5CNFSM5QBY5NOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOH4XWFZI.gifMessage ID: @.***>

-- Prof. Nicola Toschi

Associate Professor of Medical Physics Medical Physics Section - Department of Biomedicine and Prevention University of Rome "Tor Vergata" Via Montpellier 1 - 00133 Rome (IT) @.***

Research Staff, Associate Investigator A.A. Martinos Center for Biomedical Imaging - Harvard Medical School/MGH 149 13th street, 02129 Boston (MA), USA @.***

-- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

ntustison commented 2 years ago

My mistake---been doing too much in ANTsPy and I failed to see the usage here. Note that this particular format/usage of the displacement fields completely stems from ITK.

But, yes, see ConvertImage (specifically option 10):

% ConvertImage
Usage: ConvertImage imageDimension inputImage outputImage <pixelType>
pixelType:  0 -> float (default)
            1 -> unsigned char
            2 -> unsigned short
            3 -> unsigned int
            4 -> unsigned long
            5 -> char
            6 -> short
            7 -> int
            8 -> long
            9 -> component images to a float vector image
           10 -> vector image to component images
           11 -> time-varying velocity field image to component images (ImageDimension is the dimensionality of the displacement vector)
           12 -> float vector image
nicolatoschi commented 2 years ago

Work perfectly, thank you!

nicola

On 3/7/2022 1:13 AM, Nick Tustison wrote:

My mistake---been doing too much in ANTsPy and I failed to see the usage here. Note that this particular format/usage of the displacement fields completely stems from ITK.

But, yes, see |ConvertImage| (specifically option 10):

|% ConvertImage Usage: ConvertImage imageDimension inputImage outputImage pixelType: 0 -> float (default) 1 -> unsigned char 2 -> unsigned short 3 -> unsigned int 4 -> unsigned long 5 -> char 6 -> short 7 -> int 8 -> long 9 -> component images to a float vector image 10 -> vector image to component images 11 -> time-varying velocity field image to component images (ImageDimension is the dimensionality of the displacement vector) 12 -> float vector image |

— Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTs/issues/1314#issuecomment-1060072198, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFE4XESWYEFYV4FD2RZO23U6VC3TANCNFSM5QBY5NOA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Web Bug from https://github.com/notifications/beacon/AOFE4XEUJRXGQSCNNWMACQTU6VC3TA5CNFSM5QBY5NOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOH4XWWBQ.gifMessage ID: @.***>

-- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus