registration.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from nipype.interfaces import ants
  2. # Parameters for a full registration (Affine,Syn) --- SLOW ---
  3. def full_registration(fixed, moving, output='full_trans.nii', transform_pre=''):
  4. ants.Registration(
  5. dimension=2,
  6. transforms=['Rigid', 'Affine', 'SyN'],
  7. transform_parameters=[(0.15,), (0.15,), (0.3, 3, 0.5)],
  8. metric=['CC', 'MI'] * 3,
  9. convergence_threshold=[1.e-7],
  10. number_of_iterations=[[1000, 1000, 1000, 1000], [1000, 1000, 1000, 1000],
  11. [1000, 1000, 1000, 1000, 1000]],
  12. smoothing_sigmas=[[4, 4, 2, 2], [4, 4, 2, 2], [4, 2, 2, 2, 1]],
  13. shrink_factors=[[32, 16, 8, 4], [32, 16, 8, 4], [16, 8, 4, 2, 1]],
  14. initial_moving_transform_com=1,
  15. interpolation='BSpline',
  16. metric_weight=[0.5] * 6,
  17. radius_or_number_of_bins=[4,32] * 3,
  18. sampling_strategy=['Regular'] * 3,
  19. use_histogram_matching=True,
  20. winsorize_lower_quantile=0.05,
  21. winsorize_upper_quantile=0.95,
  22. collapse_output_transforms=True,
  23. output_transform_prefix=transform_pre,
  24. fixed_image=[fixed],
  25. moving_image=[moving],
  26. output_warped_image=output,
  27. num_threads=12,
  28. verbose=False,
  29. write_composite_transform=True,
  30. output_inverse_warped_image=True
  31. ).run()
  32. return output
  33. # A faster rigid registration
  34. def rigid_registration(fixed, moving, output='affine_trans.nii', transform_pre=''):
  35. ants.Registration(
  36. dimension=2,
  37. transforms=['Rigid'],
  38. transform_parameters=[(0.15,)],
  39. metric=['MI'],
  40. smoothing_sigmas=[[4, 4, 2]],
  41. convergence_threshold=[1.e-6],
  42. number_of_iterations=[[1000, 1000, 1000]],
  43. shrink_factors=[[32, 16, 8]],
  44. initial_moving_transform_com=0,
  45. interpolation='BSpline',
  46. metric_weight=[1],
  47. radius_or_number_of_bins=[32],
  48. sampling_strategy=['Regular'],
  49. use_histogram_matching=True,
  50. winsorize_lower_quantile=0.05,
  51. winsorize_upper_quantile=0.95,
  52. terminal_output='none',
  53. output_transform_prefix=transform_pre,
  54. fixed_image=[fixed],
  55. moving_image=[moving],
  56. output_warped_image=output
  57. ).run()
  58. return output