Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
itkLabelSampler.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef itkLabelSampler_h
14 #define itkLabelSampler_h
15 
16 #include <itkImageToImageFilter.h>
17 
18 namespace itk
19 {
29 template< class TImage>
30 class LabelSampler:public ImageToImageFilter< TImage, TImage >
31 {
32 public:
34  typedef LabelSampler Self;
35  typedef ImageToImageFilter< TImage, TImage > Superclass;
37  typedef std::map<int,int> outmap;
38 
40  itkNewMacro(Self);
42  itkTypeMacro(Self, ImageToImageFilter);
43  itkSetMacro(AcceptRate, double);
44  itkSetMacro(Label, int);
45  itkGetMacro(LabelVoxelCountMap, outmap);
46  itkGetMacro(NumberOfSampledVoxels,int);
47 
53  int GetLabelVoxelCount(int label)
54  {
55  if(m_LabelVoxelCountMap.empty())
56  return 0;
57  return m_LabelVoxelCountMap[label];
58  }
59 
60 protected:
62  :m_Label(-1)
63  ,m_AcceptRate(1.0)
64  ,m_UseLabelVoxelCount(false)
65  {
66  this->SetNumberOfRequiredInputs(1);
67  this->SetNumberOfRequiredOutputs(1);
68  }
69 
71 
73  virtual void GenerateData();
74 
75 private:
76  LabelSampler(const Self &); //purposely not implemented
77  void operator=(const Self &); //purposely not implemented
78 
79  int m_Label;
80  int m_NumberOfSampledVoxels;
81  double m_AcceptRate;
82  bool m_UseLabelVoxelCount;
83  std::map<int,int> m_LabelVoxelCountMap;
84 };
85 } //namespace ITK
86 
87 
88 #ifndef ITK_MANUAL_INSTANTIATION
89 #include "../src/Algorithms/itkLabelSampler.cpp"
90 #endif
91 
92 
93 #endif // itkLabelSampler_h
Randomly sub-samples voxels from a label image based on an acceptance rate.
LabelSampler Self
std::map< int, int > outmap
SmartPointer< Self > Pointer
virtual void GenerateData()
ImageToImageFilter< TImage, TImage > Superclass
int GetLabelVoxelCount(int label)
Get the voxel count for a specific label value.