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 
44 template <typename TLabelImage>
45 class ITK_TEMPLATE_EXPORT LabelOverlapMeasuresImageFilter : public ImageToImageFilter<TLabelImage, TLabelImage>
46 {
47 public:
48  ITK_DISALLOW_COPY_AND_MOVE(LabelOverlapMeasuresImageFilter);
49 
55 
57  itkNewMacro(Self);
58 
61 
63  using LabelImageType = TLabelImage;
64  using LabelImagePointer = typename TLabelImage::Pointer;
65  using LabelImageConstPointer = typename TLabelImage::ConstPointer;
66 
68  using SizeType = typename TLabelImage::SizeType;
70 
71  using LabelType = typename TLabelImage::PixelType;
72 
75 
81  {
82  public:
83  // default constructor
85  {
86  m_Source = 0;
87  m_Target = 0;
88  m_Union = 0;
89  m_Intersection = 0;
90  m_SourceComplement = 0;
91  m_TargetComplement = 0;
92  }
93 
94  // added for completeness
97  {
98  if (this != &l)
99  {
100  m_Source = l.m_Source;
101  m_Target = l.m_Target;
102  m_Union = l.m_Union;
103  m_Intersection = l.m_Intersection;
104  m_SourceComplement = l.m_SourceComplement;
105  m_TargetComplement = l.m_TargetComplement;
106  }
107  return *this;
108  }
109 
110  unsigned long m_Source;
111  unsigned long m_Target;
112  unsigned long m_Union;
113  unsigned long m_Intersection;
114  unsigned long m_SourceComplement;
115  unsigned long m_TargetComplement;
116  };
117 
119  using MapType = std::unordered_map<LabelType, LabelSetMeasures>;
120  using MapIterator = typename MapType::iterator;
121  using MapConstIterator = typename MapType::const_iterator;
122 
124  static constexpr unsigned int ImageDimension = TLabelImage::ImageDimension;
125 
127  void
129  {
130  this->SetNthInput(0, const_cast<LabelImageType *>(image));
131  }
132 
134  void
136  {
137  this->SetNthInput(1, const_cast<LabelImageType *>(image));
138  }
139 
141  const LabelImageType *
143  {
144  return this->GetInput(0);
145  }
146 
148  const LabelImageType *
150  {
151  return this->GetInput(1);
152  }
153 
155  MapType
157  {
158  return this->m_LabelSetMeasures;
159  }
160 
161  // Overlap agreement metrics
162 
164  RealType
165  GetTotalOverlap() const;
166 
168  RealType GetTargetOverlap(LabelType) const;
169 
171  RealType
172  GetUnionOverlap() const;
173  RealType
175  {
176  return this->GetUnionOverlap();
177  }
179 
182  RealType GetUnionOverlap(LabelType) const;
183  RealType
185  {
186  return this->GetUnionOverlap(label);
187  }
189 
191  RealType
192  GetMeanOverlap() const;
193  RealType
195  {
196  return this->GetMeanOverlap();
197  }
199 
202  RealType GetMeanOverlap(LabelType) const;
203  RealType
205  {
206  return this->GetMeanOverlap(label);
207  }
209 
211  RealType
212  GetVolumeSimilarity() const;
213 
215  RealType GetVolumeSimilarity(LabelType) const;
216 
217  // Overlap error metrics
218 
220  RealType
221  GetFalseNegativeError() const;
222 
224  RealType GetFalseNegativeError(LabelType) const;
225 
227  RealType
228  GetFalsePositiveError() const;
229 
231  RealType GetFalsePositiveError(LabelType) const;
232 
233 #ifdef ITK_USE_CONCEPT_CHECKING
234  // Begin concept checking
235  itkConceptMacro(Input1HasNumericTraitsCheck, (Concept::HasNumericTraits<LabelType>));
236  // End concept checking
237 #endif
238 
239 protected:
241  ~LabelOverlapMeasuresImageFilter() override = default;
242  void
243  PrintSelf(std::ostream & os, Indent indent) const override;
244 
250  void
251  AllocateOutputs() override;
252 
253  void
254  BeforeThreadedGenerateData() override;
255 
256  void
257  AfterThreadedGenerateData() override;
258 
260  void
261  ThreadedGenerateData(const RegionType &, ThreadIdType) override;
262 
263  void
265  {
266  itkExceptionMacro("This class requires threadId so it must use classic multi-threading model");
267  }
268 
269  // Override since the filter produces all of its output
270  void
271  EnlargeOutputRequestedRegion(DataObject * data) override;
272 
273 private:
274  std::vector<MapType> m_LabelSetMeasuresPerThread;
276 }; // end of class
277 
278 } // end namespace itk
279 
280 #ifndef ITK_MANUAL_INSTANTIATION
281 # include "itkLabelOverlapMeasuresImageFilter.hxx"
282 #endif
283 
284 #endif
itk::LabelOverlapMeasuresImageFilter::MapType
std::unordered_map< LabelType, LabelSetMeasures > MapType
Definition: itkLabelOverlapMeasuresImageFilter.h:119
itk::LabelOverlapMeasuresImageFilter::DynamicThreadedGenerateData
void DynamicThreadedGenerateData(const RegionType &) override
Definition: itkLabelOverlapMeasuresImageFilter.h:264
itk::LabelOverlapMeasuresImageFilter::m_LabelSetMeasuresPerThread
std::vector< MapType > m_LabelSetMeasuresPerThread
Definition: itkLabelOverlapMeasuresImageFilter.h:274
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:714
itk::LabelOverlapMeasuresImageFilter::GetJaccardCoefficient
RealType GetJaccardCoefficient() const
Definition: itkLabelOverlapMeasuresImageFilter.h:174
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_Target
unsigned long m_Target
Definition: itkLabelOverlapMeasuresImageFilter.h:111
itk::LabelOverlapMeasuresImageFilter::MapIterator
typename MapType::iterator MapIterator
Definition: itkLabelOverlapMeasuresImageFilter.h:120
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::LabelOverlapMeasuresImageFilter::LabelType
typename TLabelImage::PixelType LabelType
Definition: itkLabelOverlapMeasuresImageFilter.h:71
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::LabelOverlapMeasuresImageFilter::GetDiceCoefficient
RealType GetDiceCoefficient() const
Definition: itkLabelOverlapMeasuresImageFilter.h:194
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::operator=
LabelSetMeasures & operator=(const LabelSetMeasures &l)
Definition: itkLabelOverlapMeasuresImageFilter.h:96
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::LabelSetMeasures
LabelSetMeasures()
Definition: itkLabelOverlapMeasuresImageFilter.h:84
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_SourceComplement
unsigned long m_SourceComplement
Definition: itkLabelOverlapMeasuresImageFilter.h:114
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:65
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:128
itk::LabelOverlapMeasuresImageFilter::GetJaccardCoefficient
RealType GetJaccardCoefficient(LabelType label) const
Definition: itkLabelOverlapMeasuresImageFilter.h:184
itk::LabelOverlapMeasuresImageFilter::m_LabelSetMeasures
MapType m_LabelSetMeasures
Definition: itkLabelOverlapMeasuresImageFilter.h:275
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_Source
unsigned long m_Source
Definition: itkLabelOverlapMeasuresImageFilter.h:110
itk::LabelOverlapMeasuresImageFilter::GetTargetImage
const LabelImageType * GetTargetImage()
Definition: itkLabelOverlapMeasuresImageFilter.h:149
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_Intersection
unsigned long m_Intersection
Definition: itkLabelOverlapMeasuresImageFilter.h:113
itk::LabelOverlapMeasuresImageFilter::LabelImagePointer
typename TLabelImage::Pointer LabelImagePointer
Definition: itkLabelOverlapMeasuresImageFilter.h:64
itkImageToImageFilter.h
itk::LabelOverlapMeasuresImageFilter::GetLabelSetMeasures
MapType GetLabelSetMeasures()
Definition: itkLabelOverlapMeasuresImageFilter.h:156
itk::LabelOverlapMeasuresImageFilter::RegionType
typename TLabelImage::RegionType RegionType
Definition: itkLabelOverlapMeasuresImageFilter.h:67
itk::LabelOverlapMeasuresImageFilter::GetSourceImage
const LabelImageType * GetSourceImage()
Definition: itkLabelOverlapMeasuresImageFilter.h:142
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures
Metrics stored per label.
Definition: itkLabelOverlapMeasuresImageFilter.h:80
itk::LabelOverlapMeasuresImageFilter::GetDiceCoefficient
RealType GetDiceCoefficient(LabelType label) const
Definition: itkLabelOverlapMeasuresImageFilter.h:204
itk::LabelOverlapMeasuresImageFilter::RealType
typename NumericTraits< LabelType >::RealType RealType
Definition: itkLabelOverlapMeasuresImageFilter.h:74
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
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:112
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures::m_TargetComplement
unsigned long m_TargetComplement
Definition: itkLabelOverlapMeasuresImageFilter.h:115
itkNumericTraits.h
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:84
itk::LabelOverlapMeasuresImageFilter::IndexType
typename TLabelImage::IndexType IndexType
Definition: itkLabelOverlapMeasuresImageFilter.h:69
itk::LabelOverlapMeasuresImageFilter::SizeType
typename TLabelImage::SizeType SizeType
Definition: itkLabelOverlapMeasuresImageFilter.h:68
itk::LabelOverlapMeasuresImageFilter::SetTargetImage
void SetTargetImage(const LabelImageType *image)
Definition: itkLabelOverlapMeasuresImageFilter.h:135
itk::LabelOverlapMeasuresImageFilter::LabelImageType
TLabelImage LabelImageType
Definition: itkLabelOverlapMeasuresImageFilter.h:63
itk::LabelOverlapMeasuresImageFilter::MapConstIterator
typename MapType::const_iterator MapConstIterator
Definition: itkLabelOverlapMeasuresImageFilter.h:121
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:45