ITK/Examples/Iterators/ImageRandomConstIteratorWithIndex

From KitwarePublic
< ITK‎ | Examples
Revision as of 18:37, 24 February 2011 by Daviddoria (talk | contribs) (Created page with "==ImageRandomConstIteratorWithIndex.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageRandomConstIteratorWithIndex.h" int main(in...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

ImageRandomConstIteratorWithIndex.cxx

<source lang="cpp">

  1. include "itkImage.h"
  2. include "itkImageFileReader.h"
  3. include "itkImageRandomConstIteratorWithIndex.h"

int main(int argc, char*argv[]) {

 typedef itk::Image<unsigned char, 2>  ImageType;
 ImageType::Pointer image = ImageType::New();
 
 ImageType::SizeType regionSize;
 regionSize[0] = 5;
 regionSize[1] = 4;
 ImageType::IndexType regionIndex;
 regionIndex[0] = 0;
 regionIndex[1] = 0;
 ImageType::RegionType region;
 region.SetSize(regionSize);
 region.SetIndex(regionIndex);
 image->SetRegions(region);
 image->Allocate();
 image->FillBuffer(0);
 
 itk::ImageRandomConstIteratorWithIndex<ImageType> imageIterator(image, image->GetLargestPossibleRegion());
 imageIterator.SetNumberOfSamples(200);
 imageIterator.GoToBegin();
 
 while(!imageIterator.IsAtEnd())
   {
   std::cout << imageIterator.GetIndex() << std::endl;
   ++imageIterator;
   }
   
 return EXIT_SUCCESS;

}

</source>

CMakeLists.txt

<source lang="cmake"> cmake_minimum_required(VERSION 2.6)

PROJECT(ImageRandomConstIteratorWithIndex)

FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(ImageRandomConstIteratorWithIndex ImageRandomConstIteratorWithIndex.cxx) TARGET_LINK_LIBRARIES(ImageRandomConstIteratorWithIndex ITKNumerics ITKBasicFilters ITKCommon ITKIO)

</source>