ITK  5.2.0
Insight Toolkit
itkLabelOverlapMeasuresImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkLabelOverlapMeasuresImageFilter_h
19 #define itkLabelOverlapMeasuresImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
22 #include "itkNumericTraits.h"
23 
24 #include <unordered_map>
25 
26 namespace itk
27 {
28 
45 template <typename TLabelImage>
46 class ITK_TEMPLATE_EXPORT LabelOverlapMeasuresImageFilter : public ImageToImageFilter<TLabelImage, TLabelImage>
47 {
48 public:
49  ITK_DISALLOW_COPY_AND_MOVE(LabelOverlapMeasuresImageFilter);
50 
56 
58  itkNewMacro(Self);
59 
62 
64  using LabelImageType = TLabelImage;
65  using LabelImagePointer = typename TLabelImage::Pointer;
66  using LabelImageConstPointer = typename TLabelImage::ConstPointer;
67 
69  using SizeType = typename TLabelImage::SizeType;
71 
72  using LabelType = typename TLabelImage::PixelType;
73 
76 
82  {
83  public:
84  // default constructor
86  {
87  m_Source = 0;
88  m_Target = 0;
89  m_Union = 0;
90  m_Intersection = 0;
91  m_SourceComplement = 0;
92  m_TargetComplement = 0;
93  }
94 
95  // added for completeness
98  {
99  if (this != &l)
100  {
101  m_Source = l.m_Source;
102  m_Target = l.m_Target;
103  m_Union = l.m_Union;
104  m_Intersection = l.m_Intersection;
105  m_SourceComplement = l.m_SourceComplement;
106  m_TargetComplement = l.m_TargetComplement;
107  }
108  return *this;
109  }
110 
111  unsigned long m_Source;
112  unsigned long m_Target;
113  unsigned long m_Union;
114  unsigned long m_Intersection;
115  unsigned long m_SourceComplement;
116  unsigned long m_TargetComplement;
117  };
118 
120  using MapType = std::unordered_map<LabelType, LabelSetMeasures>;
121  using MapIterator = typename MapType::iterator;
122  using MapConstIterator = typename MapType::const_iterator;
123 
125  static constexpr unsigned int ImageDimension = TLabelImage::ImageDimension;
126 
128  void
130  {
131  this->SetNthInput(0, const_cast<LabelImageType *>(image));
132  }
133 
135  void
137  {
138  this->SetNthInput(1, const_cast<LabelImageType *>(image));
139  }
140 
142  const LabelImageType *
144  {
145  return this->GetInput(0);
146  }
147 
149  const LabelImageType *
151  {
152  return this->GetInput(1);
153  }
154 
156  MapType
158  {
159  return this->m_LabelSetMeasures;
160  }
161 
162  // Overlap agreement metrics
163 
165  RealType
166  GetTotalOverlap() const;
167 
169  RealType GetTargetOverlap(LabelType) const;
170 
172  RealType
173  GetUnionOverlap() const;
174  RealType
176  {
177  return this->GetUnionOverlap();
178  }
180 
183  RealType GetUnionOverlap(LabelType) const;
184  RealType
186  {
187  return this->GetUnionOverlap(label);
188  }
190 
192  RealType
193  GetMeanOverlap() const;
194  RealType
196  {
197  return this->GetMeanOverlap();
198  }
200 
203  RealType GetMeanOverlap(LabelType) const;
204  RealType
206  {
207  return this->GetMeanOverlap(label);
208  }
210 
212  RealType
213  GetVolumeSimilarity() const;
214 
216  RealType GetVolumeSimilarity(LabelType) const;
217 
218  // Overlap error metrics
219 
221  RealType
222  GetFalseNegativeError() const;
223 
225  RealType GetFalseNegativeError(LabelType) const;
226 
228  RealType
229  GetFalsePositiveError() const;
230 
232  RealType GetFalsePositiveError(LabelType) const;
233 
234 #ifdef ITK_USE_CONCEPT_CHECKING
235  // Begin concept checking
236  itkConceptMacro(Input1HasNumericTraitsCheck, (Concept::HasNumericTraits<LabelType>));
237  // End concept checking
238 #endif
239 
240 protected:
242  ~LabelOverlapMeasuresImageFilter() override = default;
243  void
244  PrintSelf(std::ostream & os, Indent indent) const override;
245 
251  void
252  AllocateOutputs() override;
253 
254  void
255  BeforeThreadedGenerateData() override;
256 
257  void
258  AfterThreadedGenerateData() override;
259 
261  void
262  ThreadedGenerateData(const RegionType &, ThreadIdType) override;
263 
264  void
266  {
267  itkExceptionMacro("This class requires threadId so it must use classic multi-threading model");
268  }
269 
270  // Override since the filter produces all of its output
271  void
272  EnlargeOutputRequestedRegion(DataObject * data) override;
273 
274 private:
275  std::vector<MapType> m_LabelSetMeasuresPerThread;
277 }; // end of class
278 
279 } // end namespace itk
280 
281 #ifndef ITK_MANUAL_INSTANTIATION
282 # include "itkLabelOverlapMeasuresImageFilter.hxx"
283 #endif
284 
285 #endif
itk::LabelOverlapMeasuresImageFilter::MapType
std::unordered_map< LabelType, LabelSetMeasures > MapType
Definition: itkLabelOverlapMeasuresImageFilter.h:120
itk::LabelOverlapMeasuresImageFilter::DynamicThreadedGenerateData
void DynamicThreadedGenerateData(const RegionType &) override
Definition: itkLabelOverlapMeasuresImageFilter.h:265
itk::LabelOverlapMeasuresImageFilter::m_LabelSetMeasuresPerThread
std::vector< MapType > m_LabelSetMeasuresPerThread
Definition: itkLabelOverlapMeasuresImageFilter.h:275
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:712
itk::LabelOverlapMeasuresImageFilter::GetJaccardCoefficient
RealType GetJaccardCoefficient() const
Definition: itkLabelOverlapMeasuresImageFilter.h:175
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_Target
unsigned long m_Target
Definition: itkLabelOverlapMeasuresImageFilter.h:112
itk::LabelOverlapMeasuresImageFilter::MapIterator
typename MapType::iterator MapIterator
Definition: itkLabelOverlapMeasuresImageFilter.h:121
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::LabelOverlapMeasuresImageFilter::LabelType
typename TLabelImage::PixelType LabelType
Definition: itkLabelOverlapMeasuresImageFilter.h:72
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::LabelOverlapMeasuresImageFilter::GetDiceCoefficient
RealType GetDiceCoefficient() const
Definition: itkLabelOverlapMeasuresImageFilter.h:195
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::operator=
LabelSetMeasures & operator=(const LabelSetMeasures &l)
Definition: itkLabelOverlapMeasuresImageFilter.h:97
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::LabelSetMeasures
LabelSetMeasures()
Definition: itkLabelOverlapMeasuresImageFilter.h:85
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_SourceComplement
unsigned long m_SourceComplement
Definition: itkLabelOverlapMeasuresImageFilter.h:115
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::LabelOverlapMeasuresImageFilter::LabelImageConstPointer
typename TLabelImage::ConstPointer LabelImageConstPointer
Definition: itkLabelOverlapMeasuresImageFilter.h:66
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::LabelOverlapMeasuresImageFilter::SetSourceImage
void SetSourceImage(const LabelImageType *image)
Definition: itkLabelOverlapMeasuresImageFilter.h:129
itk::LabelOverlapMeasuresImageFilter::GetJaccardCoefficient
RealType GetJaccardCoefficient(LabelType label) const
Definition: itkLabelOverlapMeasuresImageFilter.h:185
itk::LabelOverlapMeasuresImageFilter::m_LabelSetMeasures
MapType m_LabelSetMeasures
Definition: itkLabelOverlapMeasuresImageFilter.h:276
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_Source
unsigned long m_Source
Definition: itkLabelOverlapMeasuresImageFilter.h:111
itk::LabelOverlapMeasuresImageFilter::GetTargetImage
const LabelImageType * GetTargetImage()
Definition: itkLabelOverlapMeasuresImageFilter.h:150
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_Intersection
unsigned long m_Intersection
Definition: itkLabelOverlapMeasuresImageFilter.h:114
itk::LabelOverlapMeasuresImageFilter::LabelImagePointer
typename TLabelImage::Pointer LabelImagePointer
Definition: itkLabelOverlapMeasuresImageFilter.h:65
itkImageToImageFilter.h
itk::LabelOverlapMeasuresImageFilter::GetLabelSetMeasures
MapType GetLabelSetMeasures()
Definition: itkLabelOverlapMeasuresImageFilter.h:157
itk::LabelOverlapMeasuresImageFilter::RegionType
typename TLabelImage::RegionType RegionType
Definition: itkLabelOverlapMeasuresImageFilter.h:68
itk::LabelOverlapMeasuresImageFilter::GetSourceImage
const LabelImageType * GetSourceImage()
Definition: itkLabelOverlapMeasuresImageFilter.h:143
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures
Metrics stored per label.
Definition: itkLabelOverlapMeasuresImageFilter.h:81
itk::LabelOverlapMeasuresImageFilter::GetDiceCoefficient
RealType GetDiceCoefficient(LabelType label) const
Definition: itkLabelOverlapMeasuresImageFilter.h:205
itk::LabelOverlapMeasuresImageFilter::RealType
typename NumericTraits< LabelType >::RealType RealType
Definition: itkLabelOverlapMeasuresImageFilter.h:75
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:64
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_Union
unsigned long m_Union
Definition: itkLabelOverlapMeasuresImageFilter.h:113
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_TargetComplement
unsigned long m_TargetComplement
Definition: itkLabelOverlapMeasuresImageFilter.h:116
itkNumericTraits.h
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:84
itk::LabelOverlapMeasuresImageFilter::IndexType
typename TLabelImage::IndexType IndexType
Definition: itkLabelOverlapMeasuresImageFilter.h:70
itk::LabelOverlapMeasuresImageFilter::SizeType
typename TLabelImage::SizeType SizeType
Definition: itkLabelOverlapMeasuresImageFilter.h:69
itk::LabelOverlapMeasuresImageFilter::SetTargetImage
void SetTargetImage(const LabelImageType *image)
Definition: itkLabelOverlapMeasuresImageFilter.h:136
itk::LabelOverlapMeasuresImageFilter::LabelImageType
TLabelImage LabelImageType
Definition: itkLabelOverlapMeasuresImageFilter.h:64
itk::LabelOverlapMeasuresImageFilter::MapConstIterator
typename MapType::const_iterator MapConstIterator
Definition: itkLabelOverlapMeasuresImageFilter.h:122
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293
itk::LabelOverlapMeasuresImageFilter
Computes overlap measures between the set same set of labels of pixels of two images....
Definition: itkLabelOverlapMeasuresImageFilter.h:46