ITK  4.2.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  m_Source = l.m_Source;
97  m_Target = l.m_Target;
98  m_Union = l.m_Union;
99  m_Intersection = l.m_Intersection;
100  m_SourceComplement = l.m_SourceComplement;
101  m_TargetComplement = l.m_TargetComplement;
102  }
103 
104  unsigned long m_Source;
105  unsigned long m_Target;
106  unsigned long m_Union;
107  unsigned long m_Intersection;
108  unsigned long m_SourceComplement;
109  unsigned long m_TargetComplement;
110  };
111 
113  typedef itksys::hash_map<LabelType, LabelSetMeasures> MapType;
114  typedef typename MapType::iterator MapIterator;
115  typedef typename MapType::const_iterator MapConstIterator;
116 
118  itkStaticConstMacro( ImageDimension, unsigned int,
119  TLabelImage::ImageDimension );
120 
122  void SetSourceImage( const LabelImageType * image )
123  { this->SetNthInput( 0, const_cast<LabelImageType *>( image ) ); }
124 
126  void SetTargetImage( const LabelImageType * image )
127  { this->SetNthInput( 1, const_cast<LabelImageType *>( image ) ); }
128 
130  const LabelImageType * GetSourceImage( void )
131  { return this->GetInput( 0 ); }
132 
134  const LabelImageType * GetTargetImage( void )
135  { return this->GetInput( 1 ); }
136 
138  MapType GetLabelSetMeasures()
139  { return this->m_LabelSetMeasures; }
140 
146  RealType GetTotalOverlap();
147  RealType GetUnionOverlap();
148  RealType GetMeanOverlap();
149  RealType GetVolumeSimilarity();
150  RealType GetFalseNegativeError();
151  RealType GetFalsePositiveError();
152 
154  RealType GetTargetOverlap( LabelType );
155  RealType GetUnionOverlap( LabelType );
156  RealType GetMeanOverlap( LabelType );
157  RealType GetVolumeSimilarity( LabelType );
158  RealType GetFalseNegativeError( LabelType );
159  RealType GetFalsePositiveError( LabelType );
160 
162  RealType GetJaccardCoefficient()
163  { return this->GetUnionOverlap(); }
164  RealType GetJaccardCoefficient( LabelType label )
165  { return this->GetUnionOverlap( label ); }
166  RealType GetDiceCoefficient()
167  { return this->GetMeanOverlap(); }
168  RealType GetDiceCoefficient( LabelType label )
169  { return this->GetMeanOverlap( label ); }
171 
172 
173 #ifdef ITK_USE_CONCEPT_CHECKING
174 
175  itkConceptMacro( Input1HasNumericTraitsCheck,
177 
179 #endif
180 
181 protected:
184  void PrintSelf( std::ostream& os, Indent indent ) const;
185 
191  void AllocateOutputs();
192 
193  void BeforeThreadedGenerateData();
194 
195  void AfterThreadedGenerateData();
196 
198  void ThreadedGenerateData( const RegionType&, ThreadIdType );
199 
200  // Override since the filter needs all the data for the algorithm
201  void GenerateInputRequestedRegion();
202 
203  // Override since the filter produces all of its output
204  void EnlargeOutputRequestedRegion( DataObject *data );
205 
206 private:
207  LabelOverlapMeasuresImageFilter( const Self& ); //purposely not implemented
208  void operator=( const Self& ); //purposely not implemented
209 
210  std::vector<MapType> m_LabelSetMeasuresPerThread;
212 }; // end of class
213 
214 } // end namespace itk
215 
216 #ifndef ITK_MANUAL_INSTANTIATION
217 #include "itkLabelOverlapMeasuresImageFilter.hxx"
218 #endif
219 
220 #endif
221