<div dir="ltr">My Mistake not all voxels are visited in the for loop here, using <span style="color:rgb(0,0,0);font-size:10px;line-height:1.2em"> </span><span class="" style="font-size:10px;line-height:1.2em;color:rgb(0,0,255)">while</span><span class="" style="font-size:10px;line-height:1.2em;color:rgb(0,128,0)">(</span><span class="" style="font-size:10px;line-height:1.2em;color:rgb(0,0,64)">!</span><span style="color:rgb(0,0,0);font-size:10px;line-height:1.2em">imageIterator.</span><span class="" style="font-size:10px;line-height:1.2em;color:rgb(0,119,136)">IsAtEnd</span><span class="" style="font-size:10px;line-height:1.2em;color:rgb(0,128,0)">(</span><span class="" style="font-size:10px;line-height:1.2em;color:rgb(0,128,0)">)</span><span class="" style="font-size:10px;line-height:1.2em;color:rgb(0,128,0)">)</span><div>
<span class="" style="font-size:10px;line-height:1.2em;color:rgb(0,128,0)"><br></span></div><div style><span class="" style="font-size:10px;line-height:1.2em;color:rgb(0,128,0)">does the job</span></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Fri, Dec 6, 2013 at 4:04 PM, Emma Saunders <span dir="ltr"><<a href="mailto:emmasaunders123@gmail.com" target="_blank">emmasaunders123@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hi all,<div><br></div><div>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't get the full image back.</div>
<div><br></div><div>I am using the example in examples/data/brainweb1e1a10f20.mha. Below is my code, attached is my result,</div><div><br></div><div>Any ideas?</div><div><br></div><div>
<br></div><div><div>#include "itkImageFileWriter.h"</div><div>#include "itkImageFileReader.h"</div><div>#include "itkImageFileWriter.h"</div><div>#include "itkImage.h"</div><div>
#include "itkImageFileReader.h"</div><div>#include "itkImageRandomConstIteratorWithIndex.h"</div><div>#include "itkImageRandomNonRepeatingConstIteratorWithIndex.h"</div><div> </div><div>int main(int argc, char*argv[])</div>
<div>{</div><div><span style="white-space:pre-wrap"> </span></div><div> const unsigned int Dimension = 3;</div><div> typedef unsigned char PixelType;</div><div> typedef itk::Image<PixelType, Dimension> ImageType;</div>
<div><br></div><div> typedef itk::ImageFileReader< ImageType > ImageReaderType;</div><div> typedef itk::ImageFileWriter< ImageType > ImageWriterType;</div><div><br></div><div> ImageReaderType::Pointer ImageReader = ImageReaderType::New();</div>
<div> ImageWriterType::Pointer ImageWriter = ImageWriterType::New();</div><div> </div><div> ImageReader->SetFileName( argv[1] );</div><div> ImageWriter->SetFileName( argv[2] );</div><div> </div><div><br></div>
<div> ImageType::Pointer Image = ImageReader->GetOutput();</div><div> Image->Update();</div><div><br></div><div><span style="white-space:pre-wrap"> </span>ImageType::RegionType region=Image->GetLargestPossibleRegion();</div>
<div><span style="white-space:pre-wrap"> </span>ImageType::SizeType size=region.GetSize();</div><div><span style="white-space:pre-wrap"> </span>ImageType::IndexType index=region.GetIndex();</div><div> ImageType::IndexType start = index;</div>
<div> ImageType::SpacingType spacing = Image->GetSpacing();</div><div> ImageType::DirectionType direction = Image->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 << "The size of the image is " << size <<std::endl;</div><div><br></div><div>//Define Output Image</div>
<div> </div><div> ImageType::Pointer output = ImageType::New();</div><div> output->SetRegions(newregion);</div><div> output->SetSpacing(spacing);</div><div> output->SetDirection(direction);</div><div>
output->Allocate(); </div>
<div> output->FillBuffer(0);</div><div> output->Update();</div><div> </div><div> typedef itk::ImageRandomNonRepeatingConstIteratorWithIndex<</div><div> ImageType > 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 << "The number of samples is " << number << 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 <<inputIt.GetIndex()<< " " ;</div>
<div> //std::cout << inputIt.Get() << std::endl;</div><div> output->SetPixel(inputIt.GetIndex(), inputIt.Get());</div><div> </div><div> ++inputIt;</div><div> }</div><div> </div><div> output->Update();</div>
<div> ImageWriter->SetInput( output );</div><div> ImageWriter->Update();</div><div><br></div><div> </div><div> </div><div> return EXIT_SUCCESS;</div><div>}</div></div><div><br></div><div><br></div><div>
Thanks Emma</div></div>
</blockquote></div><br></div>