ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
628 stars 161 forks source link

How to change the default saved path for transform #302

Closed colddie closed 3 months ago

colddie commented 2 years ago

Hi,

After performing a registration, I found resulted transforms are automatically saved in my /tmp/ directory. Is there a way to change this behaviour?

Thanks. Tao

stnava commented 2 years ago

read through help( ants.registration )

brian

On Thu, Oct 14, 2021 at 2:52 AM Tao Sun @.***> wrote:

Hi,

After performing a registration, I found resulted transforms are automatically saved in my /tmp/ directory. Is there a way to change this behaviour?

Thanks. Tao

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTsPy/issues/302, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACPE7XFDLT2XTYUH4KWFATUGZ43FANCNFSM5F64L6XQ . 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.

17854234782 commented 2 years ago

Hi,I meet the same problem,but I don’t want to save the temporary file,What should I do?

ntustison commented 2 years ago

You have to save the files somewhere and there's an option in ants.registration which allows you to specify the location.

jcgriff1 commented 2 years ago

Hello, I'm running into the same issue. I want to save the .mat files in a specific, non-temp location, but I can't find the option to specify the location.

When I ran help( ants.registration ), I get the following:

`Help on function registration in module ants.registration.interface:

registration(fixed, moving, type_of_transform='SyN', initial_transform=None, outprefix='', mask=None, grad_step=0.2, flow_sigma=3, total_sigma=0, aff_metric='mattes', aff_sampling=32, aff_random_sampling_rate=0.2, syn_metric='mattes', syn_sampling=32, reg_iterations=(40, 20, 0), aff_iterations=(2100, 1200, 1200, 10), aff_shrink_factors=(6, 4, 2, 1), aff_smoothing_sigmas=(3, 2, 1, 0), write_composite_transform=False, random_seed=None, verbose=False, multivariate_extras=None, **kwargs) Register a pair of images either through the full or simplified interface to the ANTs registration method.

ANTsR function: `antsRegistration`

Arguments
---------
fixed : ANTsImage
    fixed image to which we register the moving image.

moving : ANTsImage
    moving image to be mapped to fixed space.

type_of_transform : string
    A linear or non-linear registration type. Mutual information metric by default.
    See Notes below for more.

initial_transform : list of strings (optional)
    transforms to prepend

outprefix : string
    output will be named with this prefix.

mask : ANTsImage (optional)
    mask the registration.

grad_step : scalar
    gradient step size (not for all tx)

flow_sigma : scalar
    smoothing for update field

total_sigma : scalar
    smoothing for total field

aff_metric : string
    the metric for the affine part (GC, mattes, meansquares)

aff_sampling : scalar
    the nbins or radius parameter for the syn metric

aff_random_sampling_rate : scalar
    the fraction of points used to estimate the metric. this can impact
    speed but also reproducibility and/or accuracy.

syn_metric : string
    the metric for the syn part (CC, mattes, meansquares, demons)

syn_sampling : scalar
    the nbins or radius parameter for the syn metric

reg_iterations : list/tuple of integers
    vector of iterations for syn. we will set the smoothing and multi-resolution parameters based on the length of this vector.

aff_iterations : list/tuple of integers
    vector of iterations for low-dimensional (translation, rigid, affine) registration.

aff_shrink_factors : list/tuple of integers
    vector of multi-resolution shrink factors for low-dimensional (translation, rigid, affine) registration.

aff_smoothing_sigmas : list/tuple of integers
    vector of multi-resolution smoothing factors for low-dimensional (translation, rigid, affine) registration.

random_seed : integer
    random seed to improve reproducibility. note that the number of ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS should be 1 if you want perfect reproducibility.

write_composite_transform : boolean
    Boolean specifying whether or not the composite transform (and its inverse, if it exists) should be written to an hdf5 composite file. This is false by default so that only the transform for each stage is written to file.

verbose : boolean
    request verbose output (useful for debugging)

multivariate_extras : additional metrics for multi-metric registration
    list of additional images and metrics which will
    trigger the use of multiple metrics in the registration
    process in the deformable stage. Each multivariate metric needs 5
    entries: name of metric, fixed, moving, weight,
    samplingParam. the list of lists should be of the form ( (
    "nameOfMetric2", img, img, weight, metricParam ) ). Another
    example would be  ( ( "MeanSquares", f2, m2, 0.5, 0
      ), ( "CC", f2, m2, 0.5, 2 ) ) .  This is only compatible
    with the SyNOnly transformation.

kwargs : keyword args
    extra arguments

Returns
-------
dict containing follow key/value pairs:
    `warpedmovout`: Moving image warped to space of fixed image.
    `warpedfixout`: Fixed image warped to space of moving image.
    `fwdtransforms`: Transforms to move from moving to fixed image.
    `invtransforms`: Transforms to move from fixed to moving image.

Notes
-----
type_of_transform can be one of:
    - "Translation": Translation transformation.
    - "Rigid": Rigid transformation: Only rotation and translation.
    - "Similarity": Similarity transformation: scaling, rotation and translation.
    - "QuickRigid": Rigid transformation: Only rotation and translation.
                    May be useful for quick visualization fixes.'
    - "DenseRigid": Rigid transformation: Only rotation and translation.
                    Employs dense sampling during metric estimation.'
    - "BOLDRigid": Rigid transformation: Parameters typical for BOLD to
                    BOLD intrasubject registration'.'
    - "Affine": Affine transformation: Rigid + scaling.
    - "AffineFast": Fast version of Affine.
    - "BOLDAffine": Affine transformation: Parameters typical for BOLD to
                    BOLD intrasubject registration'.'
    - "TRSAA": translation, rigid, similarity, affine (twice). please set
                regIterations if using this option. this would be used in
                cases where you want a really high quality affine mapping
                (perhaps with mask).
    - "Elastic": Elastic deformation: Affine + deformable.
    - "ElasticSyN": Symmetric normalization: Affine + deformable
                    transformation, with mutual information as optimization
                    metric and elastic regularization.
    - "SyN": Symmetric normalization: Affine + deformable transformation,
                with mutual information as optimization metric.
    - "SyNRA": Symmetric normalization: Rigid + Affine + deformable
                transformation, with mutual information as optimization metric.
    - "SyNOnly": Symmetric normalization: no initial transformation,
                with mutual information as optimization metric. Assumes
                images are aligned by an inital transformation. Can be
                useful if you want to run an unmasked affine followed by
                masked deformable registration.
    - "SyNCC": SyN, but with cross-correlation as the metric.
    - "SyNabp": SyN optimized for abpBrainExtraction.
    - "SyNBold": SyN, but optimized for registrations between BOLD and T1 images.
    - "SyNBoldAff": SyN, but optimized for registrations between BOLD
                    and T1 images, with additional affine step.
    - "SyNAggro": SyN, but with more aggressive registration
                    (fine-scale matching and more deformation).
                    Takes more time than SyN.
    - "TV[n]": time-varying diffeomorphism with where 'n' indicates number of
        time points in velocity field discretization.  The initial transform
        should be computed, if needed, in a separate call to ants.registration.
    - "TVMSQ": time-varying diffeomorphism with mean square metric
    - "TVMSQC": time-varying diffeomorphism with mean square metric for very large deformation
    - "antsRegistrationSyN[x]": recreation of the antsRegistrationSyN.sh script in ANTs
                                where 'x' is one of the transforms available (e.g., 't', 'b', 's')
    - "antsRegistrationSyNQuick[x]": recreation of the antsRegistrationSyNQuick.sh script in ANTs
                                where 'x' is one of the transforms available (e.g., 't', 'b', 's')
    - "antsRegistrationSyNRepro[x]": reproducible registration.  x options as above.
    - "antsRegistrationSyNQuickRepro[x]": quick reproducible registration.  x options as above.

Example
-------
>>> import ants
>>> fi = ants.image_read(ants.get_ants_data('r16'))
>>> mi = ants.image_read(ants.get_ants_data('r64'))
>>> fi = ants.resample_image(fi, (60,60), 1, 0)
>>> mi = ants.resample_image(mi, (60,60), 1, 0)
>>> mytx = ants.registration(fixed=fi, moving=mi, type_of_transform = 'SyN' )

`

Unless I am missing something, there is nothing here indicating that there is an option to change the save directory. Could you please clarify how to set this option?

stnava commented 2 years ago

outprefix : string output will be named with this prefix.

brian

On Tue, Dec 28, 2021 at 3:23 PM jcgriff1 @.***> wrote:

Hello, I'm running into the same issue. I want to save the .mat files in a specific, non-temp location, but I can't find the option to specify the location.

When I ran help( ants.registration ), I get the following:

`Help on function registration in module ants.registration.interface:

registration(fixed, moving, type_of_transform='SyN', initial_transform=None, outprefix='', mask=None, grad_step=0.2, flow_sigma=3, total_sigma=0, aff_metric='mattes', aff_sampling=32, aff_random_sampling_rate=0.2, syn_metric='mattes', syn_sampling=32, reg_iterations=(40, 20, 0), aff_iterations=(2100, 1200, 1200, 10), aff_shrink_factors=(6, 4, 2, 1), aff_smoothing_sigmas=(3, 2, 1, 0), write_composite_transform=False, random_seed=None, verbose=False, multivariate_extras=None, **kwargs) Register a pair of images either through the full or simplified interface to the ANTs registration method.

ANTsR function: antsRegistration

Arguments

fixed : ANTsImage fixed image to which we register the moving image.

moving : ANTsImage moving image to be mapped to fixed space.

type_of_transform : string A linear or non-linear registration type. Mutual information metric by default. See Notes below for more.

initial_transform : list of strings (optional) transforms to prepend

outprefix : string output will be named with this prefix.

mask : ANTsImage (optional) mask the registration.

grad_step : scalar gradient step size (not for all tx)

flow_sigma : scalar smoothing for update field

total_sigma : scalar smoothing for total field

aff_metric : string the metric for the affine part (GC, mattes, meansquares)

aff_sampling : scalar the nbins or radius parameter for the syn metric

aff_random_sampling_rate : scalar the fraction of points used to estimate the metric. this can impact speed but also reproducibility and/or accuracy.

syn_metric : string the metric for the syn part (CC, mattes, meansquares, demons)

syn_sampling : scalar the nbins or radius parameter for the syn metric

reg_iterations : list/tuple of integers vector of iterations for syn. we will set the smoothing and multi-resolution parameters based on the length of this vector.

aff_iterations : list/tuple of integers vector of iterations for low-dimensional (translation, rigid, affine) registration.

aff_shrink_factors : list/tuple of integers vector of multi-resolution shrink factors for low-dimensional (translation, rigid, affine) registration.

aff_smoothing_sigmas : list/tuple of integers vector of multi-resolution smoothing factors for low-dimensional (translation, rigid, affine) registration.

random_seed : integer random seed to improve reproducibility. note that the number of ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS should be 1 if you want perfect reproducibility.

write_composite_transform : boolean Boolean specifying whether or not the composite transform (and its inverse, if it exists) should be written to an hdf5 composite file. This is false by default so that only the transform for each stage is written to file.

verbose : boolean request verbose output (useful for debugging)

multivariate_extras : additional metrics for multi-metric registration list of additional images and metrics which will trigger the use of multiple metrics in the registration process in the deformable stage. Each multivariate metric needs 5 entries: name of metric, fixed, moving, weight, samplingParam. the list of lists should be of the form ( ( "nameOfMetric2", img, img, weight, metricParam ) ). Another example would be ( ( "MeanSquares", f2, m2, 0.5, 0 ), ( "CC", f2, m2, 0.5, 2 ) ) . This is only compatible with the SyNOnly transformation.

kwargs : keyword args extra arguments

Returns

dict containing follow key/value pairs: warpedmovout: Moving image warped to space of fixed image. warpedfixout: Fixed image warped to space of moving image. fwdtransforms: Transforms to move from moving to fixed image. invtransforms: Transforms to move from fixed to moving image.

Notes

type_of_transform can be one of:

  • "Translation": Translation transformation.
  • "Rigid": Rigid transformation: Only rotation and translation.
  • "Similarity": Similarity transformation: scaling, rotation and translation.
  • "QuickRigid": Rigid transformation: Only rotation and translation. May be useful for quick visualization fixes.'
  • "DenseRigid": Rigid transformation: Only rotation and translation. Employs dense sampling during metric estimation.'
  • "BOLDRigid": Rigid transformation: Parameters typical for BOLD to BOLD intrasubject registration'.'
  • "Affine": Affine transformation: Rigid + scaling.
  • "AffineFast": Fast version of Affine.
  • "BOLDAffine": Affine transformation: Parameters typical for BOLD to BOLD intrasubject registration'.'
  • "TRSAA": translation, rigid, similarity, affine (twice). please set regIterations if using this option. this would be used in cases where you want a really high quality affine mapping (perhaps with mask).
  • "Elastic": Elastic deformation: Affine + deformable.
  • "ElasticSyN": Symmetric normalization: Affine + deformable transformation, with mutual information as optimization metric and elastic regularization.
  • "SyN": Symmetric normalization: Affine + deformable transformation, with mutual information as optimization metric.
  • "SyNRA": Symmetric normalization: Rigid + Affine + deformable transformation, with mutual information as optimization metric.
  • "SyNOnly": Symmetric normalization: no initial transformation, with mutual information as optimization metric. Assumes images are aligned by an inital transformation. Can be useful if you want to run an unmasked affine followed by masked deformable registration.
  • "SyNCC": SyN, but with cross-correlation as the metric.
  • "SyNabp": SyN optimized for abpBrainExtraction.
  • "SyNBold": SyN, but optimized for registrations between BOLD and T1 images.
  • "SyNBoldAff": SyN, but optimized for registrations between BOLD and T1 images, with additional affine step.
  • "SyNAggro": SyN, but with more aggressive registration (fine-scale matching and more deformation). Takes more time than SyN.
  • "TV[n]": time-varying diffeomorphism with where 'n' indicates number of time points in velocity field discretization. The initial transform should be computed, if needed, in a separate call to ants.registration.
  • "TVMSQ": time-varying diffeomorphism with mean square metric
  • "TVMSQC": time-varying diffeomorphism with mean square metric for very large deformation
  • "antsRegistrationSyN[x]": recreation of the antsRegistrationSyN.sh script in ANTs where 'x' is one of the transforms available (e.g., 't', 'b', 's')
  • "antsRegistrationSyNQuick[x]": recreation of the antsRegistrationSyNQuick.sh script in ANTs where 'x' is one of the transforms available (e.g., 't', 'b', 's')
  • "antsRegistrationSyNRepro[x]": reproducible registration. x options as above.
  • "antsRegistrationSyNQuickRepro[x]": quick reproducible registration. x options as above.

Example

import ants fi = ants.image_read(ants.get_ants_data('r16')) mi = ants.image_read(ants.get_ants_data('r64')) fi = ants.resample_image(fi, (60,60), 1, 0) mi = ants.resample_image(mi, (60,60), 1, 0) mytx = ants.registration(fixed=fi, moving=mi, type_of_transform = 'SyN' )

`

Unless I am missing something, there is nothing here indicating that there is an option to change the save directory. Could you please clarify how to set this option?

— Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTsPy/issues/302#issuecomment-1002268439, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACPE7QSEL6DS5TJ3QV5D33UTIMCTANCNFSM5F64L6XQ . 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 commented.Message ID: @.***>

jcgriff1 commented 2 years ago

Thank you - does this change the location that the output will be saved to, or will it still be output to a temp directory?

ntustison commented 2 years ago

Outputprefix includes path information

jcgriff1 commented 2 years ago

Ok, thank you!