<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'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 "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 class="" style="white-space:pre"> </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 class="" style="white-space:pre"> </span>ImageType::RegionType region=Image->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->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 style>//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 style><br></div><div style><br></div><div style>
Thanks Emma</div></div>