// Parameter file for affine registration
// as used in: Artaechevarria X, Munoz-Barrutia A, Ortiz-de-Solorzano C., 
// "Combination strategies in multi-atlas image segmentation: application to brain MR data,"
// IEEE Trans Med Imaging. 2009 Aug;28(8):1266-77.

// The internal pixel type, used for computations
// Leave to float in general
(FixedInternalImagePixelType "float")
(MovingInternalImagePixelType "float")

// The dimensions of the fixed and moving image
(FixedImageDimension 3)
(MovingImageDimension 3)

//Components

// The following components should be left as they are:
(Registration "MultiResolutionRegistration")
(FixedImagePyramid "FixedRecursiveImagePyramid")
(MovingImagePyramid "MovingRecursiveImagePyramid")
(Interpolator "BSplineInterpolator")
(ResampleInterpolator "FinalBSplineInterpolator")
(Resampler "DefaultResampler")

// You may change these:
// The optimizer RegularStepGradientDescent (RSGD) works quite ok 
// in general. You may also use the StandardGradientDescent,
// like in parameters_Rigid.txt. The Transform and Metric
// are important and need to be chosen careful for each application.
(Optimizer "RegularStepGradientDescent")
(Transform "AffineTransform")
(Metric "AdvancedMattesMutualInformation")

// Scales the rotations compared to the translations, to make
// sure they are in the same range. The higher this parameter,
// the smaller the changes in rotation angle in each iteration.
// If you have the feeling that rotations are not found by elastix,
// decrease it; if elastix crashes after a few iterations, with
// the message that all samples map outside the moving image 
// buffer, you may have to increase this parameter.
(Scales 50000.0)

// Automatically guess an initial translation. Not needed/recommended
// here, because we already did a rigid registration before!
(AutomaticTransformInitialization "false")

// Choose another center of rotation for the AffineTransform,
// if you like. Uncomment if you want that.
//(CenterOfRotation 10 10 10)

// The number of resolutions. 1 Is only enough if the expected
// deformations are small. 3 or 4 mostly works fine.
(NumberOfResolutions 3)

// The pixel type of the resulting image
(ResultImagePixelType "short")

// If you use a mask, this option is important. You can 
// set it for each resolution differently.
// If the mask serves as region of interest, set it to false.
// If the mask indicates which pixels are valid, then set it to true.
// If you do not use a mask, the option doesn't matter.
(ErodeMask "false" "false" "false")

// Whether transforms are combined by composition or by addition.
// In general, Compose is the best option in most cases.
// It does not influence the results very much.
(HowToCombineTransforms "Compose")

//Save composite ITK transform
(ITKTransformOutputFileNameExtension "h5")
(WriteITKCompositeTransform "true")

// Number of spatial samples used to compute the mutual
// information in each resolution level.
// With the RegularStepGradientDescentOptimizer in general
// you need to set this to some fixed fraction of the total 
// number of voxels in the image. Say 20%, at least.
// In the first resolutions the images are smaller so you 
// may use less samples.
(NumberOfSpatialSamples 30000 80000 100000)

// Pick the samples (pseudo)randomly. Use "Full" if you want
// to use all voxels to compute metric. (then the previous 
// option makes of course no sense anymore).
(ImageSampler "Random")

// Number of grey level bins in each resolution level,
// for the mutual information. 16 or 32 usually works fine.
(NumberOfHistogramBins 16 32 32)

//Order of B-Spline interpolation used in each resolution level:
// It may improve accuracy if you set this to 3. Never use 0.
(BSplineInterpolationOrder 2 2 2)

//Order of B-Spline interpolation used for applying the final
// deformation.
// 3 gives good accuracy.
// 1 gives worse accuracy (linear interpolation)
// 0 gives worst accuracy, but may be appropriate for 
// binary images; this would be equivalent to nearest neighbor
// interpolation.
(FinalBSplineInterpolationOrder 0)

//Default pixel value for pixels that come from outside the picture:
(DefaultPixelValue 0)

// The following parameters are for the StandardGradientDescent
// optimizer. They determine the step size.
// Especially SP_a needs to be tuned for each specific application.
// The number of iterations is also important.

//Maximum number of iterations in each resolution level:
// 100-500 works usually fine.
(MaximumNumberOfIterations 100 100 100)

//Maximum step size of the RSGD optimizer for each resolution level.
// The higher you set this, the more aggressive steps are taken.
(MaximumStepLength 4.0 2.0 2.0)

//Minimum step size of the RSGD optimizer for each resolution level.
// The lower you set this, the more accurate the final result.
//(MinimumStepLength 0.5 0.05 0.05)
(MinimumStepLength 0.5 0.05 0.05)

//Minimum magnitude of the gradient (stopping criterion) for the RSGD optimizer:
// The lower you set this, the more accurate the final result may be.
(MinimumGradientMagnitude 0.00000001 0.00000001 0.00000001)


//Result image format
(ResultImageFormat "mhd")
