//Parameter file

//**********ImageTypes**********

// The internal pixel type, used for internal computations
// Leave to float in general. 
// NB: this is not the type of the input images! The pixel 
// type of the input images is automatically read from the 
// images themselves.
// This setting can be changed to "short" to save some memory
// in case of very large 3D images.
(FixedInternalImagePixelType "float")
(MovingInternalImagePixelType "float")

//*********Components**********

(Registration "MultiResolutionRegistration")

//***Interpolator
//(Interpolator "BSplineInterpolator")
(Interpolator "LinearInterpolator")
//***Resampler
(Resampler "DefaultResampler")
(ResampleInterpolator "FinalBSplineInterpolator")
//(ResampleInterpolator "LinearInterpolator")

(FixedImagePyramid "FixedRecursiveImagePyramid")
(MovingImagePyramid "MovingRecursiveImagePyramid")
//(FixedImagePyramid "FixedSmoothingImagePyramid")
//(MovingImagePyramid "MovingSmoothingImagePyramid")
//(FixedImagePyramid "FixedShrinkingImagePyramid")
//(MovingImagePyramid "MovingShrinkingImagePyramid")

// The following components are most important:
// The optimizer AdaptiveStochasticGradientDescent (ASGD) works
// quite ok in general. The Transform and Metric are important
// and need to be chosen careful for each application. See manual.
(Transform "EulerTransform")
(Sampler "RandomCoordinate")
(Optimizer "AdaptiveStochasticGradientDescent")
(Metric "AdvancedMattesMutualInformation")

//************Transform************

// Scales the rotations compared to the translations, to make
// sure they are in the same range. In general, it's best to  
// use automatic scales estimation:
(AutomaticScalesEstimation "true")

// Automatically guess an initial translation by aligning the
// geometric centers of the fixed and moving.
(AutomaticTransformInitialization "true")

// Whether transforms are combined by composition or by addition.
// In generally, 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")
//(AutomaticTransformInitializationMethod "CenterOfGravity")


//************Similarity Measure************

// Number of grey level bins in each resolution level,
// for the mutual information. 16 or 32 usually works fine.
// You could also employ a hierarchical strategy:
(NumberOfHistogramBins 16 32 32 64)
//(NumberOfHistogramBins 32)


//**************Multiresolution **********************

// The number of resolutions. 1 Is only enough if the expected
// deformations are small. 3 or 4 mostly works fine. For large
// images and large deformations, 5 or 6 may even be useful.
(NumberOfResolutions 4)
(ImagePyramidSchedule 8 8 8  4 4 4  2 2 2  1 1 1 )
//(FinalGridSpacingInVoxels 1.0 1.0 1.0)
//(GridSpacingSchedule 6.0 6.0 6.0 3.0 3.0 3.0 1.0 1.0 1.0)
// Make sure that the number of elements equals the number
// of resolutions times the image dimension


// ******************* Optimizer ****************************

// Maximum number of iterations in each resolution level:
// 200-500 works usually fine for rigid registration.
// For more robustness, you may increase this to 1000-2000.
(MaximumNumberOfIterations 1000 1000 1500 1500)

// The step size of the optimizer, in mm. By default the voxel size is used.
// which usually works well. In case of unusual high-resolution images
// (eg histology) it is necessary to increase this value a bit, to the size
// of the "smallest visible structure" in the image:
//(MaximumStepLength 1.0)


//************Image Sampling************

// Number of spatial samples used to compute the mutual
// information (and its derivative) in each iteration.
// With an AdaptiveStochasticGradientDescent optimizer,
// in combination with the two options below, around 2000
// samples may already suffice.
(NumberOfSpatialSamples 2048)

// Refresh these spatial samples in every iteration, and select
// them randomly. See the manual for information on other sampling
// strategies.
(NewSamplesEveryIteration "true")
(ImageSampler "RandomCoordinate")

(FixedImageBSplineInterpolationOrder 1)
(UseRandomSampleRegion "true")
//(SampleRegionSize 50 50 50)

// ************* Interpolation and Resampling ****************

// Order of B-Spline interpolation used during registration/optimisation.
// It may improve accuracy if you set this to 3. Never use 0.
// An order of 1 gives linear interpolation. This is in most 
// applications a good choice.
(BSplineInterpolationOrder 1)

// Order of B-Spline interpolation used for applying the final
// deformation.
// 3 gives good accuracy; recommended in most cases.
// 1 gives worse accuracy (linear interpolation)
// 0 gives worst accuracy, but is appropriate for binary images
// (masks, segmentations); equivalent to nearest neighbor interpolation.
(FinalBSplineInterpolationOrder 3)

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

//************Output***************

// Write resulting images. You can save some time by setting this to false, if you are only interested in the final deformed moving image for example.
(WriteResultImage "true")

//***********MiscVisulaization
(WriteTransformParametersEachIteration "false" "false" "false" "false")
(WriteTransformParametersEachResolution "true" "true" "true" "true")

// Define output format
//(ResultImagePixelType "double") 
(ResultImageFormat "mhd")
