13 #ifndef itkLabelSampler_cpp 14 #define itkLabelSampler_cpp 17 #include "itkObjectFactory.h" 18 #include "itkImageRegionIterator.h" 19 #include "itkImageRegionConstIterator.h" 20 #include "itkImageIterator.h" 21 #include "itkImageConstIterator.h" 29 template<
class TImage>
35 srand (time(
nullptr));
36 this->AllocateOutputs();
38 typename TImage::ConstPointer input = this->GetInput();
39 TImage * output = this->GetOutput();
41 m_NumberOfSampledVoxels = 0;
43 ImageRegionConstIterator<TImage> inputIter(input, input->GetLargestPossibleRegion());
44 ImageRegionIterator<TImage> outputIter(output, output->GetLargestPossibleRegion());
45 while (!inputIter.IsAtEnd())
47 if (inputIter.Get() > 0)
50 if(m_LabelVoxelCountMap.find(inputIter.Get()) == m_LabelVoxelCountMap.end())
51 m_LabelVoxelCountMap[inputIter.Get()] = 0;
52 m_LabelVoxelCountMap[inputIter.Get()]++;
55 if(inputIter.Get() == m_Label || m_Label == -1 ){
56 r = (double)(rand()) / RAND_MAX;
59 outputIter.Set(inputIter.Get());
60 m_NumberOfSampledVoxels++;
78 #endif // itkLabelSampler_cpp
virtual void GenerateData()