# SlicerANTs antsRegistration in Slicer

**URL:** <https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842>\
**Category:** Development\
**Tags:** registration, feature\
**Created:** [May 28, 2021, 2:19pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842 "2021-05-28T14:19:11Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [May 28, 2021, 2:19pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/1 "2021-05-28T14:19:11Z")

</div>

Hi,

Just made a PR to ExtensionsIndex to add [SlicerANTs](https://github.com/simonoxen/SlicerANTs) extension, which implements antsRegistration.

Probably needs some fixes, but it’s currently functional.

This effort is based on the following:

- [ANTs has publications supporting it’s accuracy](https://github.com/ANTsX/ANTs)
- Allows for using multiple metrics. (For example using multiple MRI sequences to normalise to MNI).
- Highly customisable (I guess this is pro and con depending on the user level)

I tried to keep it understandable despite the vast amount of parameters it has. Any feedback is welcome!

I used a json string as a parameter in the parameter node to keep up with this amount of settings. Also, I stored presets as json files so loading them is straightforward. Is this a good practice?

It was mostly based on the [SlicerElastix](https://github.com/lassoan/SlicerElastix) implementation, from which I copied parts of code.

Best

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [May 28, 2021, 4:53pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/2 "2021-05-28T16:53:34Z")

</div>

This is great. Do you have it for windows platform too?

---

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [May 31, 2021, 6:31am UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/3 "2021-05-31T06:31:47Z")

</div>

yes, it builds, but there’s still work needed to integrate with Slicer ITK

---

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [June 18, 2021, 10:37am UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/4 "2021-06-18T10:37:48Z")

</div>

Hi, just tested with latest nightly in win, mac and ubuntu and is working! Thanks @lassoan for the contributions during the PR!

Further work includes:

- Merging compilation modifications back to ants repo so as to checkout from there.
- Making the Advanced section more robust (currently could run to some errors with some settings if not familiarised).
- Adding more presets.

Hope this is helpful

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [June 18, 2021, 12:53pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/5 "2021-06-18T12:53:34Z")

</div>

Failed! A problem with my software.

win 64

# 

antsCommand standard error:

Traceback (most recent call last):  
File “E:/Slicer/Slicer41120210226/OpenExtentions/SlicerANTs-master/antsCommand/antsCommand.py”, line 131, in  
process = runAntsCommand(antsExecutable, antsCommand, outputLogPath)  
File “E:/Slicer/Slicer41120210226/OpenExtentions/SlicerANTs-master/antsCommand/antsCommand.py”, line 12, in runAntsCommand  
executableFilePath = os.path.join(getAntsBinDir(), executableFileName)  
File “E:/Slicer/Slicer41120210226/OpenExtentions/SlicerANTs-master/antsCommand/antsCommand.py”, line 55, in getAntsBinDir  
raise ValueError(‘ANTs not found’)  
ValueError: ANTs not found

#

---

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [June 18, 2021, 1:15pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/6 "2021-06-18T13:15:39Z")

</div>

hi, doesn’t seem you installed via Extension Manager in latest nightly

Best

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [June 18, 2021, 1:18pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/7 "2021-06-18T13:18:57Z")

</div>

I downloaded it from Github，then installed it via developer Tools.

---

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [June 18, 2021, 1:20pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/8 "2021-06-18T13:20:22Z")

</div>

You need to install via Extension Manager from a nightly build (starting today)

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [June 20, 2021, 12:30am UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/9 "2021-06-20T00:30:04Z")

</div>

@simonoxen I tried with the latest build and it seems to work fine, thank you this nice work. It is great to be able to explore the parameters and visualize the outcome in the same place.

Can you consider saving/outputting the actual antsRegistration call somewhere, so that we can use that parameter set directly on with ANTs or ANTsR when we are running a large number of samples programmatically?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 20, 2021, 7:52pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/10 "2021-06-20T19:52:40Z")

</div>

@simonoxen The module is intuitive and fast and works very robustly. Thanks a lot for your contribution! It would be great if you could create a short YouTube video that shows a few basic and maybe some more advanced use cases in 1-2 minutes.

@muratmaga you can find the command line argument list that is passed to ants in the application log.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [June 20, 2021, 7:59pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/11 "2021-06-20T19:59:33Z")

</div>

> [@lassoan](#):
>
> @muratmaga you can find the command line argument list that is passed to ants in the application log.

I know but it is always better to write them explicitly to disk (in json or whatever) for posterity. If I close the application, I may loose the parameters (I know the logs exists for a while, but still…)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 20, 2021, 9:13pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/12 "2021-06-20T21:13:39Z")

</div>

If you created one or a few files at each execution of ANTS, when those file would be deleted? (you don’t want to end up with potentially hundreds of temporary files if you perform registration many times)

Saving the parameters into the log is nice because the last 10-15 log files are preserved but older ones are cleaned up automatically. You would normally get the parameters right after the successful registration anyway, so it should not be even necessary to dig into the archived log files.

---

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [June 21, 2021, 6:41am UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/13 "2021-06-21T06:41:04Z")

</div>

Thanks!

> [@lassoan](#):
>
> It would be great if you could create a short YouTube video that shows a few basic and maybe some more advanced use cases in 1-2 minutes.

I’ll add this to my to-do.

@muratmaga I didn’t think about it, but the log files seem to be a good solution.

---

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [November 8, 2021, 4:36pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/14 "2021-11-08T16:36:56Z")

</div>

Hi, I made some changes in the implementation of this extension.

- I made a [small contribution](https://github.com/ANTsX/ANTs/pull/1260) to the ANTs project and now I checkout from there.
- ANTs is built with shared libraries and linked to a new [antsRegistrationCLI module](https://github.com/netstim/SlicerANTs/tree/master/antsRegistrationCLI).
- ANTs is [patched](https://github.com/netstim/SlicerANTs/blob/master/SuperBuild/ants_patch.cmake) to communicate CLI progress with Slicer.
- The CLI modules manages all the I/O making the implementation much cleaner.
- I also migrated the repo to the [netstim](https://github.com/netstim) organization and made a [PR](https://github.com/Slicer/ExtensionsIndex/pull/1797) to update this is in the Extension Index.

One question I had is wether shared or static libraries is preferred to build an external project (ANTs in this case). Any comments on this?

Thanks

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 8, 2021, 5:01pm UTC](https://discourse.slicer.org/t/slicerants-antsregistration-in-slicer/17842/15 "2021-11-08T17:01:00Z")

</div>

> [@simonoxen](#):
>
> One question I had is wether shared or static libraries is preferred to build an external project (ANTs in this case). Any comments on this?

Often the maintainers of a library has a preference (they mainly test with statically-linked or shared libraries) and if that’s the case then we follow that. If there is no preference then the decision factors include expected binary compatibility issues (if the library is widely used as a shared library in different projects and no name mangling is supported then it is safer to link statically) and binary size (if the library size is big and the project provides many executables then shared libraries can cut down the size very significantly).

Since we only use a single executable and binary compatibility might come up as an issue when Slicer is used in a workflow that already uses ANTs, it might make sense to link statically.

> [@simonoxen](#):
>
> > [@lassoan](#):
> >
> > It would be great if you could create a short YouTube video that shows a few basic and maybe some more advanced use cases in 1-2 minutes.
> 
> I’ll add this to my to-do.

This would be really nice if you could do this. If you wrote a short post about the module (in “Support” category, with “feature” tag added) and included a short video demo/tutorial then we could advertise this further on twitter etc. and the impact of your work would be increased a lot. Thanks again for your contribution!
