# Sampling strategy in ImageRegistrationMethodv4

**URL:** <https://discourse.itk.org/t/sampling-strategy-in-imageregistrationmethodv4/1038>\
**Category:** Algorithms\
**Created:** [June 27, 2018, 8:00am UTC](https://discourse.itk.org/t/sampling-strategy-in-imageregistrationmethodv4/1038 "2018-06-27T08:00:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HsuehWen](https://discourse.itk.org/user_avatar/discourse.itk.org/hsuehwen/32/1453_2.png) [@HsuehWen](https://discourse.itk.org/u/HsuehWen)\
**Post date:** [June 27, 2018, 8:00am UTC](https://discourse.itk.org/t/sampling-strategy-in-imageregistrationmethodv4/1038/1 "2018-06-27T08:00:53Z")

</div>

Hi,

I see user can set sampling rate for image registration by the function “SetMetricSamplingPercentage”  
If I understand correctly, after setting the sample rate, ITK will randomly choose a set of points and evaluate metric on those points. The set of points is fixed during iteration.

My question is, is there a way to use different sample for every iteration?  
Or am I wrong that it is resampled every iteration?

---

<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:** [June 28, 2018, 2:11pm UTC](https://discourse.itk.org/t/sampling-strategy-in-imageregistrationmethodv4/1038/2 "2018-06-28T14:11:13Z")

</div>

There are 3 sampling strategies implemented: [None, Regular, and Random](https://itk.org/Doxygen/html/classitk_1_1ImageRegistrationMethodv4.html#a9f7ae6d4af58fa9a578e9af6f92b1fc9) I have always wanted to try a “poisson distributed sampling”, but I doubt it’d make a difference.

The ITKv3 registration created a new sample set each iterations.

This is not an option for ITKv4. Having a fix sample set enables coherent results for the values and the derivatives of the metric which adheres better to the assumptions of many optimizers and convergence criteria.

---

<div class="post-metadata">

**Author:** ![HsuehWen](https://discourse.itk.org/user_avatar/discourse.itk.org/hsuehwen/32/1453_2.png) [@HsuehWen](https://discourse.itk.org/u/HsuehWen)\
**Post date:** [June 29, 2018, 2:30am UTC](https://discourse.itk.org/t/sampling-strategy-in-imageregistrationmethodv4/1038/3 "2018-06-29T02:30:34Z")

</div>

Thanks @blowekamp!  
Is there a way to create new sample at every iteration in ITKv4?  
I would rather give it a try.

The images I like to registrate contains detailed structure that I think only sampling part of the points might be biased from ground truth. But I would like to speed up by sampling, or in other words, I would like to try stochastic gradient descent.  
I hope I can use techniques like momentum to stabilize the optimization.

---

<div class="post-metadata">

**Author:** ![HsuehWen](https://discourse.itk.org/user_avatar/discourse.itk.org/hsuehwen/32/1453_2.png) [@HsuehWen](https://discourse.itk.org/u/HsuehWen)\
**Post date:** [June 29, 2018, 8:48am UTC](https://discourse.itk.org/t/sampling-strategy-in-imageregistrationmethodv4/1038/4 "2018-06-29T08:48:06Z")

</div>

Well, I worked out a way to update the sample through observer.  
The result isn’t better neither worse in my case.  
Thanks for help!
