[Insight-users] ImageRandomNonRepeatingConstIteratorWithIndex repeatability

Julien Malik julien.malik at c-s.fr
Thu Mar 18 10:05:24 EDT 2010


Hello,

I'm experiencing a problem with 
itk::ImageRandomNonRepeatingConstIteratorWithIndex.

I need the following feature :
[1] iterate on an image by choosing randomly and uniformly a subset of 
pixels of predefined size.
[2] later, i need to iterate on other images (of the same size of 
course) and iterate on the same set of pixels chosen by the previous 
walk, in the same order : basically, i need to 'replay' the iterations 
done in [1]

I found itk::ImageRandomNonRepeatingConstIteratorWithIndex to be a very 
elegant solution to my problem.
For [1], no problem : this is exactly what it does (using 
SetNumberOfSamples to iterate only on a fraction of the image).
For [2], using ReinitializeSeed(int) with the same seed as in [1] seems 
to be the way to go. With that, I only need to save the seed to be able 
to regenerate the same iterations.

Now the problems :
* [BUG] when i use 
itk::ImageRandomNonRepeatingConstIteratorWithIndex::ReinitializeSeed(int) 
with the same seed in [1] and [2], i don't get the same set of pixels 
selected.
I found that modifying RandomPermutation::ReinitializeSeed(int) from
"m_Generator->Initialize(seed);"
to
"m_Generator->SetSeed(seed);"
solves my problem. It seems there is some kind of buffered data in the 
MersenneTwisterGenerator, and SetSeed calls Initialize + a reload() 
method that must clear those buffered data.

* [Feature Request] the constructor of 
ImageRandomNonRepeatingConstIteratorWithIndex creates a permutation 
internally so that the iterator is ready to walk the image. Calling 
ReinitializeSeed recreate the permutation, involving the generation of a 
random number for each pixel in the region + a std::sort of all these 
random numbers.
For performance, it would be nice to have an additionnal constructor 
where the seed can be explicitely specified.


Can you confirm the bug ? Or am I doing something wrong ?
If needed, I can provide code demonstrating the non-repeatability of the 
iterator.


Regards,
Julien



More information about the Insight-users mailing list