ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLabelOverlapMeasuresImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 "itksys/hash_map.hxx"
25 
26 namespace itk {
27 
44 template<typename TLabelImage>
45 class ITK_TEMPLATE_EXPORT LabelOverlapMeasuresImageFilter :
46  public ImageToImageFilter<TLabelImage, TLabelImage>
47 {
48 public:
49  ITK_DISALLOW_COPY_AND_ASSIGN(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
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 = itksys::hash_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 SetSourceImage( const LabelImageType * image )
128  { this->SetNthInput( 0, const_cast<LabelImageType *>( image ) ); }
129 
131  void SetTargetImage( const LabelImageType * image )
132  { this->SetNthInput( 1, const_cast<LabelImageType *>( image ) ); }
133 
136  { return this->GetInput( 0 ); }
137 
140  { return this->GetInput( 1 ); }
141 
144  { return this->m_LabelSetMeasures; }
145 
146  // Overlap agreement metrics
147 
149  RealType GetTotalOverlap() const;
150 
152  RealType GetTargetOverlap( LabelType ) const;
153 
155  RealType GetUnionOverlap() const;
157  { return this->GetUnionOverlap(); }
159 
162  RealType GetUnionOverlap( LabelType ) const;
164  { return this->GetUnionOverlap( label ); }
166 
168  RealType GetMeanOverlap() const;
170  { return this->GetMeanOverlap(); }
172 
175  RealType GetMeanOverlap( LabelType ) const;
177  { return this->GetMeanOverlap( label ); }
179 
181  RealType GetVolumeSimilarity() const;
182 
184  RealType GetVolumeSimilarity( LabelType ) const;
185 
186  // Overlap error metrics
187 
189  RealType GetFalseNegativeError() const;
190 
192  RealType GetFalseNegativeError( LabelType ) const;
193 
195  RealType GetFalsePositiveError() const;
196 
198  RealType GetFalsePositiveError( LabelType ) const;
199 
200 #ifdef ITK_USE_CONCEPT_CHECKING
201  // Begin concept checking
202  itkConceptMacro( Input1HasNumericTraitsCheck,
204  // End concept checking
205 #endif
206 
207 protected:
209  ~LabelOverlapMeasuresImageFilter() override = default;
210  void PrintSelf( std::ostream& os, Indent indent ) const override;
211 
217  void AllocateOutputs() override;
218 
219  void BeforeThreadedGenerateData() override;
220 
221  void AfterThreadedGenerateData() override;
222 
224  void ThreadedGenerateData( const RegionType&, ThreadIdType ) override;
225 
226  void DynamicThreadedGenerateData( const RegionType & ) override
227  {
228  itkExceptionMacro("This class requires threadId so it must use classic multi-threading model");
229  }
230 
231  // Override since the filter produces all of its output
232  void EnlargeOutputRequestedRegion( DataObject *data ) override;
233 
234 private:
235  std::vector<MapType> m_LabelSetMeasuresPerThread;
237 }; // end of class
238 
239 } // end namespace itk
240 
241 #ifndef ITK_MANUAL_INSTANTIATION
242 #include "itkLabelOverlapMeasuresImageFilter.hxx"
243 #endif
244 
245 #endif
Light weight base class for most itk classes.
Define numeric traits for std::vector.
typename NumericTraits< LabelType >::RealType RealType
typename TLabelImage::ConstPointer LabelImageConstPointer
void DynamicThreadedGenerateData(const RegionType &) override
RealType GetJaccardCoefficient(LabelType label) const
Computes overlap measures between the set same set of labels of pixels of two images. Background is assumed to be 0.
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itksys::hash_map< LabelType, LabelSetMeasures > MapType
#define itkConceptMacro(name, concept)
Base class for all data objects in ITK.