# Reproducibility of image registration

**URL:** https://discourse.itk.org/t/reproducibility-of-image-registration/1591
**Category:** Uncategorized
**Tags:** registration
**Created:** [February 11, 2019, 9:55am UTC](https://discourse.itk.org/t/reproducibility-of-image-registration/1591 "2019-02-11T09:55:58Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![take5v](https://discourse.itk.org/user_avatar/discourse.itk.org/take5v/32/548_2.png) [@take5v](https://discourse.itk.org/u/take5v)
#### Post date: [February 11, 2019, 9:55am UTC](https://discourse.itk.org/t/reproducibility-of-image-registration/1591/1 "2019-02-11T09:55:58Z")

</div>

Hi,

I’ve done the registration of microscopical images with affine transform using conjugate gradient line search. I observe small to a large variation in the results after several complete the same runs. Metric is Mattes Mutual Information (bins=50), sampling strategy - regular. Initialization is based on manual landmarks. Images are in the float16 format.

Questions are:

1. Where the randomness take place at the optimization procedure?
2. How to make registration procedure reproducible?

Best regards,  
Stas

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [February 11, 2019, 2:10pm UTC](https://discourse.itk.org/t/reproducibility-of-image-registration/1591/2 "2019-02-11T14:10:56Z")

</div>

It sounds like you are using the ITKv4 registration frame work. Look for methods in the classes that allow for setting for “Seeds”. For example the [itk::ImageRegistrationMethodv4::MetricSamplingReinitializeSeed](https://itk.org/Doxygen/html/classitk_1_1ImageRegistrationMethodv4.html#ab1ae25c0b7ef720a7743c3c828eeca6c) method. By default the sampling seed is initialized from from wall clock to produce random results.

If you are seeing significant difference in your registration results based on the sampling, your registration in not robust. You many be optimizing to different local minima or not properly converging. Steps to improving robustness include, more samples, using a multi-scale approach, and ensuring you optimizer is using the appropriate scales and parameters.

---

<div class="post-metadata">

### Author: ![take5v](https://discourse.itk.org/user_avatar/discourse.itk.org/take5v/32/548_2.png) [@take5v](https://discourse.itk.org/u/take5v)
#### Post date: [February 11, 2019, 2:29pm UTC](https://discourse.itk.org/t/reproducibility-of-image-registration/1591/3 "2019-02-11T14:29:40Z")

</div>

Thank you! But I’m using “REGULAR” and not “RANDOM” sampling strategy which should not use any random variables. What could be an issue then?

btw My setup also includes sitk, multi-scale approach, scales and learning rate estimator.

Best regards,  
Stas

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [February 11, 2019, 2:33pm UTC](https://discourse.itk.org/t/reproducibility-of-image-registration/1591/4 "2019-02-11T14:33:18Z")

</div>

> <https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Registration/RegistrationMethodsv4/include/itkImageRegistrationMethodv4.hxx#L964-L991>

---

<div class="post-metadata">

### Author: ![take5v](https://discourse.itk.org/user_avatar/discourse.itk.org/take5v/32/548_2.png) [@take5v](https://discourse.itk.org/u/take5v)
#### Post date: [February 13, 2019, 2:21pm UTC](https://discourse.itk.org/t/reproducibility-of-image-registration/1591/5 "2019-02-13T14:21:53Z")

</div>

Hi,

Thank you for the link to a code!

Since I’m using sitk I fixed the seed with the following:  
registration\_method SetMetricSamplingPercentage(1, 42)

But still I got tiny (hundredth of a pixel size) difference in TRE’s.

How can I fix the seed in sitk?

Best regards,  
Stas

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [February 13, 2019, 6:56pm UTC](https://discourse.itk.org/t/reproducibility-of-image-registration/1591/6 "2019-02-13T18:56:27Z")

</div>

That sounds like a fairly small amount. I would look for additional sources of randomness or light numeric differences. The next things to consider:

- What metric are you using? Does that introduce any additional randomness/numeric issues?
- How many threads/workers are you using? Perhaps try 1 via ProcessObject::SetNumberOfThreads() and ProcessObject::SetGlobalDefaultNumberOfThreads.

---

<div class="post-metadata">

### Author: ![take5v](https://discourse.itk.org/user_avatar/discourse.itk.org/take5v/32/548_2.png) [@take5v](https://discourse.itk.org/u/take5v)
#### Post date: [February 14, 2019, 9:03am UTC](https://discourse.itk.org/t/reproducibility-of-image-registration/1591/7 "2019-02-14T09:03:22Z")

</div>

Hi,

- Metric is MattesMutualInformation (bins=50), also I switched image format to float64.
- I’m using 20 cores. I’ll try also computing on 1 core. Can you please give me a hint of why it could be an issue?

Thanks for your advice!

Best regards,  
Stas

---

<div class="post-metadata">

### Author: ![take5v](https://discourse.itk.org/user_avatar/discourse.itk.org/take5v/32/548_2.png) [@take5v](https://discourse.itk.org/u/take5v)
#### Post date: [February 22, 2019, 1:59pm UTC](https://discourse.itk.org/t/reproducibility-of-image-registration/1591/8 "2019-02-22T13:59:45Z")

</div>

I’ve also found the link regarding reproducibility in ANTs. I guess ANTs registration is based on ITK as well.

> **[ANTsX/ANTs](https://github.com/ANTsX/ANTs/wiki/antsRegistration-reproducibility-issues)**
>
> Advanced Normalization Tools (ANTs) . Contribute to ANTsX/ANTs development by creating an account on GitHub.

Best regards,  
Stas
