ITK/Examples/Iterators/ImageRandomConstIteratorWithIndex: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Update example according to PR #10: https://github.com/InsightSoftwareConsortium/ITKWikiExamples/pull/10/files)
(Deprecated content that is moved to sphinxe)
 
Line 1: Line 1:
==ImageRandomConstIteratorWithIndex.cxx==
{{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.
 
}}
<source lang="cpp">
 
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageRandomConstIteratorWithIndex.h"
 
int main(int, char *[])
{
  using ImageType = itk::Image<unsigned char, 2>;
  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>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 14:14, 6 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.