SimpleITK icon indicating copy to clipboard operation
SimpleITK copied to clipboard

[question] how to replicate a ridig registration done with ANTs / niftyreg

Open neuronflow opened this issue 1 year ago • 4 comments

I am exploring whether we can replace an ANTs / niftyreg registration step in our pipelines with sitk. Which parameters would I need to replicate the functionality of:

reg_aladin \
    -rigOnly \
    -ref $fixed \
    -flo $moving \
    -res $transformed \
    -aff $matrix \
    -pad 0

ANTs we call with the following parameters:

if transformationalgorithm == "rigid":
        # rigid ants_transformation
        transform_rigid = "-t rigid[0.1]"
        metric_rigid = "-m Mattes[" + fixed_image + "," + moving_image + ", 1, 32, Regular, 0.5]"
        convergence_rigid = "-c [1000x500x250, 1e-6, 10]"
        smoothing_sigmas_rigid = "-s 3x2x1vox"
        shrink_factors_rigid = "-f 8x4x2"

Thanks for your help!

neuronflow avatar Jul 26 '23 15:07 neuronflow

Hello @neuronflow,

Most likely this is doable, rigid registration/Mattes Mutual Information/multi-resolution. The ANTs commandline parameters all look very similar to the settings in SimpleITK. Please take a look at this jupyter notebook. Specifically, the Initial Alignment and Version 2 of the final registration.

zivy avatar Jul 26 '23 16:07 zivy

Thanks for the quick response. In our case, we are trying to register 3D brain MR across modalities. If we understood you correctly we should use:

initialize: geometry
transform: euler
metric: mattes

?

neuronflow avatar Jul 26 '23 18:07 neuronflow

The specifics listed are trying to mimic the settings you are using with the ANTs command-line. You will probably have to modify the settings slightly to account for differences with ITK/SimpleITK, but generally speaking all the code you need is in the referenced notebook. Specifically:

  • transform_rigid = "-t rigid[0.1]" maps to Euler3DTransform
  • metric_rigid = "-m Mattes[" + fixed_image + "," + moving_image + ", 1, 32, Regular, 0.5] maps to SetMetricAsMattesMutualInformation, not sure what the parameters are, but they likely match the settings for the MI metric (number of histogram bins, sampling strategy and sampling percentage).
  • convergence_rigid = "-c [1000x500x250, 1e-6, 10]" maps to settings for SetOptimizerAsGradientDescent (possibly some other optimizer, but try this one for a start).
  • smoothing_sigmas_rigid = "-s 3x2x1vox" maps to SetSmoothingSigmasPerLevel
  • shrink_factors_rigid = "-f 8x4x2" maps to SetShrinkFactorsPerLevel

The only other parameter that isn't part of the registration is -pad 0 which is likely used by the resampling, after registration. Use zero as the value outside the image. That is the default behavior in the SimpleITK resampling code, so no need to specify unless you want to change it (see docs for resampling class and procedural interface).

Also, the initialization is not specified so likely it is "geometry" which is one of the more straightforward initialization approaches. Registration initialization is critical for success, see this notebook for discussion.

zivy avatar Jul 26 '23 19:07 zivy

Thank you so much!

You are right, Apologies, I failed to provide the whole call. Here is the rest we have in place:

    dimensionality = "-d 3"
    initial_moving_transform = "-r [" + fixed_image + ", " + moving_image + ", 0]"
    
    ..
    
    use_estimate_learning_rate_once = "-l 1"
    collapse_output_transforms = "-z 1"
    interpolation = "-n BSpline[3]"
    precision = "--float 1"
    output = "-o " + "[" + outputmat + "]"
    ```

neuronflow avatar Jul 26 '23 22:07 neuronflow