[ITK Community] [Insight-users] ImageRandomNonRepeatingConstIteratorWithIndex Bug ?

Emma Saunders emmasaunders123 at gmail.com
Fri Dec 6 11:04:34 EST 2013


Hi all,

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.

I am using the example in examples/data/brainweb1e1a10f20.mha.  Below is my
code, attached is my result,

Any ideas?


#include "itkImageFileWriter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageRandomConstIteratorWithIndex.h"
#include "itkImageRandomNonRepeatingConstIteratorWithIndex.h"

int main(int argc, char*argv[])
{
  const    unsigned int    Dimension = 3;
  typedef unsigned char PixelType;
  typedef itk::Image<PixelType, Dimension>  ImageType;

  typedef itk::ImageFileReader< ImageType  > ImageReaderType;
  typedef itk::ImageFileWriter< ImageType  > ImageWriterType;

  ImageReaderType::Pointer ImageReader   = ImageReaderType::New();
  ImageWriterType::Pointer ImageWriter =  ImageWriterType::New();

  ImageReader->SetFileName( argv[1] );
  ImageWriter->SetFileName( argv[2] );


    ImageType::Pointer Image = ImageReader->GetOutput();
    Image->Update();

ImageType::RegionType region=Image->GetLargestPossibleRegion();
ImageType::SizeType size=region.GetSize();
ImageType::IndexType index=region.GetIndex();
    ImageType::IndexType start = index;
    ImageType::SpacingType   spacing   = Image->GetSpacing();
    ImageType::DirectionType direction = Image->GetDirection();


    ImageType::RegionType newregion;
    newregion.SetSize(size);
    newregion.SetIndex(start);
    std::cout << "The size of the image is " << size <<std::endl;

//Define Output Image

  ImageType::Pointer output = ImageType::New();
  output->SetRegions(newregion);
  output->SetSpacing(spacing);
  output->SetDirection(direction);
  output->Allocate();
  output->FillBuffer(0);
  output->Update();

 typedef itk::ImageRandomNonRepeatingConstIteratorWithIndex<
                                          ImageType > ConstIteratorType;


  ConstIteratorType inputIt(  Image,  region );

   unsigned int number = 7069860;
  inputIt.SetNumberOfSamples( number ); //Number of samples total is 3281040
  std::cout << "The number of samples is " << number << std::endl;
  inputIt.ReinitializeSeed();
  inputIt.GoToBegin();


  //while(!inputIt.IsAtEnd())
  for ( inputIt.GoToBegin(); ! inputIt.IsAtEnd(); ++inputIt)
    {

    //std::cout <<inputIt.GetIndex()<< " " ;
    //std::cout << inputIt.Get() << std::endl;
    output->SetPixel(inputIt.GetIndex(), inputIt.Get());

    ++inputIt;
    }

  output->Update();
  ImageWriter->SetInput( output );
  ImageWriter->Update();



  return EXIT_SUCCESS;
}


Thanks Emma
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20131206/72976f5a/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SampleExample.png
Type: image/png
Size: 147121 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/community/attachments/20131206/72976f5a/attachment-0001.png>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users


More information about the Community mailing list