ITK  6.0.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  * https://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 "itkImageSink.h"
22 #include "itkNumericTraits.h"
23 #include <mutex>
24 #include <unordered_map>
25 
26 namespace itk
27 {
28 
44 template <typename TLabelImage>
45 class ITK_TEMPLATE_EXPORT LabelOverlapMeasuresImageFilter : public ImageSink<TLabelImage>
46 {
47 public:
48  ITK_DISALLOW_COPY_AND_MOVE(LabelOverlapMeasuresImageFilter);
49 
55 
57  itkNewMacro(Self);
58 
60  itkOverrideGetNameOfClassMacro(LabelOverlapMeasuresImageFilter);
61 
63  using LabelImageType = TLabelImage;
66 
68  using SizeType = typename TLabelImage::SizeType;
70 
71  using LabelType = typename TLabelImage::PixelType;
72 
75 
81  {
82  public:
83  // default constructor/copy/move etc...
84 
85  SizeValueType m_Source{ 0 };
86  SizeValueType m_Target{ 0 };
87  SizeValueType m_Union{ 0 };
88  SizeValueType m_Intersection{ 0 };
89  SizeValueType m_SourceComplement{ 0 };
90  SizeValueType m_TargetComplement{ 0 };
91  };
92 
94  using MapType = std::unordered_map<LabelType, LabelSetMeasures>;
95  using MapIterator = typename MapType::iterator;
96  using MapConstIterator = typename MapType::const_iterator;
97 
99  static constexpr unsigned int ImageDimension = TLabelImage::ImageDimension;
100 
102  itkSetInputMacro(TargetImage, LabelImageType);
103  itkGetInputMacro(TargetImage, LabelImageType);
104  itkSetInputMacro(SourceImage, LabelImageType);
105  itkGetInputMacro(SourceImage, LabelImageType);
110  MapType
112  {
113  return this->m_LabelSetMeasures;
114  }
115 
116  // Overlap agreement metrics
117 
119  RealType
120  GetTotalOverlap() const;
121 
123  RealType GetTargetOverlap(LabelType) const;
124 
126  RealType
127  GetUnionOverlap() const;
128  RealType
130  {
131  return this->GetUnionOverlap();
132  }
137  RealType GetUnionOverlap(LabelType) const;
138  RealType
140  {
141  return this->GetUnionOverlap(label);
142  }
146  RealType
147  GetMeanOverlap() const;
148  RealType
150  {
151  return this->GetMeanOverlap();
152  }
157  RealType GetMeanOverlap(LabelType) const;
158  RealType
160  {
161  return this->GetMeanOverlap(label);
162  }
166  RealType
167  GetVolumeSimilarity() const;
168 
170  RealType GetVolumeSimilarity(LabelType) const;
171 
172  // Overlap error metrics
173 
175  RealType
176  GetFalseNegativeError() const;
177 
179  RealType GetFalseNegativeError(LabelType) const;
180 
182  RealType
183  GetFalsePositiveError() const;
184 
186  RealType GetFalsePositiveError(LabelType) const;
187 
189  RealType
190  GetFalseDiscoveryRate() const;
191 
193  RealType GetFalseDiscoveryRate(LabelType) const;
194 
195 #ifdef ITK_USE_CONCEPT_CHECKING
196  // Begin concept checking
197  itkConceptMacro(Input1HasNumericTraitsCheck, (Concept::HasNumericTraits<LabelType>));
198  // End concept checking
199 #endif
200 
201 protected:
203  ~LabelOverlapMeasuresImageFilter() override = default;
204 
207 
208  void
209  PrintSelf(std::ostream & os, Indent indent) const override;
210 
211  void
212  BeforeStreamedGenerateData() override;
213 
214  void
215  ThreadedStreamedGenerateData(const RegionType &) override;
216 
217  void
218  MergeMap(MapType & m1, MapType & m2) const;
219 
220 private:
221  MapType m_LabelSetMeasures{};
222 
223  std::mutex m_Mutex{};
224 }; // end of class
225 
226 } // end namespace itk
227 
228 #ifndef ITK_MANUAL_INSTANTIATION
229 # include "itkLabelOverlapMeasuresImageFilter.hxx"
230 #endif
231 
232 #endif
itk::LabelOverlapMeasuresImageFilter::MapType
std::unordered_map< LabelType, LabelSetMeasures > MapType
Definition: itkLabelOverlapMeasuresImageFilter.h:94
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:717
itk::LabelOverlapMeasuresImageFilter::GetJaccardCoefficient
RealType GetJaccardCoefficient() const
Definition: itkLabelOverlapMeasuresImageFilter.h:129
itk::LabelOverlapMeasuresImageFilter::MapIterator
typename MapType::iterator MapIterator
Definition: itkLabelOverlapMeasuresImageFilter.h:95
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:149
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::LabelOverlapMeasuresImageFilter::LabelImageConstPointer
typename TLabelImage::ConstPointer LabelImageConstPointer
Definition: itkLabelOverlapMeasuresImageFilter.h:65
itkImageSink.h
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::LabelOverlapMeasuresImageFilter::GetJaccardCoefficient
RealType GetJaccardCoefficient(LabelType label) const
Definition: itkLabelOverlapMeasuresImageFilter.h:139
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::NumericTraits::PrintType
T PrintType
Definition: itkNumericTraits.h:70
itk::LabelOverlapMeasuresImageFilter::LabelImagePointer
typename TLabelImage::Pointer LabelImagePointer
Definition: itkLabelOverlapMeasuresImageFilter.h:64
itk::LabelOverlapMeasuresImageFilter::GetLabelSetMeasures
MapType GetLabelSetMeasures()
Definition: itkLabelOverlapMeasuresImageFilter.h:111
itk::LabelOverlapMeasuresImageFilter::RegionType
typename TLabelImage::RegionType RegionType
Definition: itkLabelOverlapMeasuresImageFilter.h:67
itk::LabelOverlapMeasuresImageFilter::LabelSetMeasures
Metrics stored per label.
Definition: itkLabelOverlapMeasuresImageFilter.h:80
itk::LabelOverlapMeasuresImageFilter::GetDiceCoefficient
RealType GetDiceCoefficient(LabelType label) const
Definition: itkLabelOverlapMeasuresImageFilter.h:159
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: itkAnatomicalOrientation.h:29
itk::LabelOverlapMeasuresImageFilter::PrintType
typename NumericTraits< LabelType >::PrintType PrintType
Definition: itkLabelOverlapMeasuresImageFilter.h:206
itkNumericTraits.h
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:86
itk::LabelOverlapMeasuresImageFilter::IndexType
typename TLabelImage::IndexType IndexType
Definition: itkLabelOverlapMeasuresImageFilter.h:69
itk::LabelOverlapMeasuresImageFilter::SizeType
typename TLabelImage::SizeType SizeType
Definition: itkLabelOverlapMeasuresImageFilter.h:68
itk::ImageSink
Definition: itkImageSink.h:53
itk::LabelOverlapMeasuresImageFilter::LabelImageType
TLabelImage LabelImageType
Definition: itkLabelOverlapMeasuresImageFilter.h:63
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::LabelOverlapMeasuresImageFilter::MapConstIterator
typename MapType::const_iterator MapConstIterator
Definition: itkLabelOverlapMeasuresImageFilter.h:96
itk::LabelOverlapMeasuresImageFilter
Computes overlap measures between the same set of labels of pixels of two images. Background is assum...
Definition: itkLabelOverlapMeasuresImageFilter.h:45