ITK  4.4.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<class TLabelImage>
46  public ImageToImageFilter<TLabelImage, TLabelImage>
47 {
48 public:
54 
56  itkNewMacro( Self );
57 
60 
62  typedef TLabelImage LabelImageType;
63  typedef typename TLabelImage::Pointer LabelImagePointer;
64  typedef typename TLabelImage::ConstPointer LabelImageConstPointer;
65 
66  typedef typename TLabelImage::RegionType RegionType;
67  typedef typename TLabelImage::SizeType SizeType;
68  typedef typename TLabelImage::IndexType IndexType;
69 
70  typedef typename TLabelImage::PixelType LabelType;
71 
74 
80  {
81  public:
82  // default constructor
84  {
85  m_Source = 0;
86  m_Target = 0;
87  m_Union = 0;
88  m_Intersection = 0;
89  m_SourceComplement = 0;
90  m_TargetComplement = 0;
91  }
92 
93  // added for completeness
94  LabelSetMeasures& operator=( const LabelSetMeasures& l )
95  {
96  if(this != &l)
97  {
98  m_Source = l.m_Source;
99  m_Target = l.m_Target;
100  m_Union = l.m_Union;
101  m_Intersection = l.m_Intersection;
102  m_SourceComplement = l.m_SourceComplement;
103  m_TargetComplement = l.m_TargetComplement;
104  }
105  return *this;
106  }
107 
108  unsigned long m_Source;
109  unsigned long m_Target;
110  unsigned long m_Union;
111  unsigned long m_Intersection;
112  unsigned long m_SourceComplement;
113  unsigned long m_TargetComplement;
114  };
115 
117  typedef itksys::hash_map<LabelType, LabelSetMeasures> MapType;
118  typedef typename MapType::iterator MapIterator;
119  typedef typename MapType::const_iterator MapConstIterator;
120 
122  itkStaticConstMacro( ImageDimension, unsigned int,
123  TLabelImage::ImageDimension );
124 
126  void SetSourceImage( const LabelImageType * image )
127  { this->SetNthInput( 0, const_cast<LabelImageType *>( image ) ); }
128 
130  void SetTargetImage( const LabelImageType * image )
131  { this->SetNthInput( 1, const_cast<LabelImageType *>( image ) ); }
132 
134  const LabelImageType * GetSourceImage( void )
135  { return this->GetInput( 0 ); }
136 
138  const LabelImageType * GetTargetImage( void )
139  { return this->GetInput( 1 ); }
140 
142  MapType GetLabelSetMeasures()
143  { return this->m_LabelSetMeasures; }
144 
150  RealType GetTotalOverlap();
151  RealType GetUnionOverlap();
152  RealType GetMeanOverlap();
153  RealType GetVolumeSimilarity();
154  RealType GetFalseNegativeError();
155  RealType GetFalsePositiveError();
156 
158  RealType GetTargetOverlap( LabelType );
159  RealType GetUnionOverlap( LabelType );
160  RealType GetMeanOverlap( LabelType );
161  RealType GetVolumeSimilarity( LabelType );
162  RealType GetFalseNegativeError( LabelType );
163  RealType GetFalsePositiveError( LabelType );
164 
166  RealType GetJaccardCoefficient()
167  { return this->GetUnionOverlap(); }
168  RealType GetJaccardCoefficient( LabelType label )
169  { return this->GetUnionOverlap( label ); }
170  RealType GetDiceCoefficient()
171  { return this->GetMeanOverlap(); }
172  RealType GetDiceCoefficient( LabelType label )
173  { return this->GetMeanOverlap( label ); }
175 
176 
177 #ifdef ITK_USE_CONCEPT_CHECKING
178 
179  itkConceptMacro( Input1HasNumericTraitsCheck,
181 
183 #endif
184 
185 protected:
188  void PrintSelf( std::ostream& os, Indent indent ) const;
189 
195  void AllocateOutputs();
196 
197  void BeforeThreadedGenerateData();
198 
199  void AfterThreadedGenerateData();
200 
202  void ThreadedGenerateData( const RegionType&, ThreadIdType );
203 
204  // Override since the filter needs all the data for the algorithm
205  void GenerateInputRequestedRegion();
206 
207  // Override since the filter produces all of its output
208  void EnlargeOutputRequestedRegion( DataObject *data );
209 
210 private:
211  LabelOverlapMeasuresImageFilter( const Self& ); //purposely not implemented
212  void operator=( const Self& ); //purposely not implemented
213 
214  std::vector<MapType> m_LabelSetMeasuresPerThread;
216 }; // end of class
217 
218 } // end namespace itk
219 
220 #ifndef ITK_MANUAL_INSTANTIATION
221 #include "itkLabelOverlapMeasuresImageFilter.hxx"
222 #endif
223 
224 #endif
225