<div dir="ltr">Hi all,<div><br></div><div style>I am using the  ImageRandomNonRepeatingConstIteratorWithIndex to randomly sample images without repeat.  When using the number of samples as the size of the image however I don&#39;t get the full image back.</div>
<div style><br></div><div style>I am using the example in examples/data/brainweb1e1a10f20.mha.  Below is my code, attached is my result,</div><div style><br></div><div style>Any ideas?</div><div style><br></div><div style>
<br></div><div style><div>#include &quot;itkImageFileWriter.h&quot;</div><div>#include &quot;itkImageFileReader.h&quot;</div><div>#include &quot;itkImageFileWriter.h&quot;</div><div>#include &quot;itkImage.h&quot;</div><div>
#include &quot;itkImageFileReader.h&quot;</div><div>#include &quot;itkImageRandomConstIteratorWithIndex.h&quot;</div><div>#include &quot;itkImageRandomNonRepeatingConstIteratorWithIndex.h&quot;</div><div> </div><div>int main(int argc, char*argv[])</div>
<div>{</div><div><span class="" style="white-space:pre">        </span></div><div>  const    unsigned int    Dimension = 3;</div><div>  typedef unsigned char PixelType;</div><div>  typedef itk::Image&lt;PixelType, Dimension&gt;  ImageType;</div>
<div><br></div><div>  typedef itk::ImageFileReader&lt; ImageType  &gt; ImageReaderType;</div><div>  typedef itk::ImageFileWriter&lt; ImageType  &gt; ImageWriterType;</div><div><br></div><div>  ImageReaderType::Pointer ImageReader   = ImageReaderType::New();</div>
<div>  ImageWriterType::Pointer ImageWriter =  ImageWriterType::New();</div><div>    </div><div>  ImageReader-&gt;SetFileName( argv[1] );</div><div>  ImageWriter-&gt;SetFileName( argv[2] );</div><div>  </div><div><br></div>
<div>    ImageType::Pointer Image = ImageReader-&gt;GetOutput();</div><div>    Image-&gt;Update();</div><div><br></div><div><span class="" style="white-space:pre">        </span>ImageType::RegionType region=Image-&gt;GetLargestPossibleRegion();</div>
<div><span class="" style="white-space:pre">        </span>ImageType::SizeType size=region.GetSize();</div><div><span class="" style="white-space:pre">        </span>ImageType::IndexType index=region.GetIndex();</div><div>    ImageType::IndexType start = index;</div>
<div>    ImageType::SpacingType   spacing   = Image-&gt;GetSpacing();</div><div>    ImageType::DirectionType direction = Image-&gt;GetDirection();</div><div><br></div><div><br></div><div>    ImageType::RegionType newregion;</div>
<div>    newregion.SetSize(size);</div><div>    newregion.SetIndex(start);</div><div>    std::cout &lt;&lt; &quot;The size of the image is &quot; &lt;&lt; size &lt;&lt;std::endl;</div><div><br></div><div style>//Define Output Image</div>
<div>        </div><div>  ImageType::Pointer output = ImageType::New();</div><div>  output-&gt;SetRegions(newregion);</div><div>  output-&gt;SetSpacing(spacing);</div><div>  output-&gt;SetDirection(direction);</div><div>  output-&gt;Allocate();   </div>
<div>  output-&gt;FillBuffer(0);</div><div>  output-&gt;Update();</div><div>                                     </div><div> typedef itk::ImageRandomNonRepeatingConstIteratorWithIndex&lt;</div><div>                                          ImageType &gt; ConstIteratorType;</div>
<div>                                          </div><div>                                        </div><div>  ConstIteratorType inputIt(  Image,  region );</div><div><br></div><div>   unsigned int number = 7069860;</div>
<div>  inputIt.SetNumberOfSamples( number ); //Number of samples total is 3281040</div><div>  std::cout &lt;&lt; &quot;The number of samples is &quot; &lt;&lt; number &lt;&lt; std::endl;</div><div>  inputIt.ReinitializeSeed();</div>
<div>  inputIt.GoToBegin();</div><div>    </div><div>       </div><div>  //while(!inputIt.IsAtEnd())</div><div>  for ( inputIt.GoToBegin(); ! inputIt.IsAtEnd(); ++inputIt)</div><div>    {</div><div>    </div><div>    //std::cout &lt;&lt;inputIt.GetIndex()&lt;&lt; &quot; &quot; ;</div>
<div>    //std::cout &lt;&lt; inputIt.Get() &lt;&lt; std::endl;</div><div>    output-&gt;SetPixel(inputIt.GetIndex(), inputIt.Get());</div><div>    </div><div>    ++inputIt;</div><div>    }</div><div>    </div><div>  output-&gt;Update();</div>
<div>  ImageWriter-&gt;SetInput( output );</div><div>  ImageWriter-&gt;Update();</div><div><br></div><div> </div><div> </div><div>  return EXIT_SUCCESS;</div><div>}</div></div><div style><br></div><div style><br></div><div style>
Thanks Emma</div></div>