ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkLabelOverlapMeasuresImageFilter_h 00019 #define __itkLabelOverlapMeasuresImageFilter_h 00020 00021 #include "itkImageToImageFilter.h" 00022 #include "itkNumericTraits.h" 00023 00024 #include "itksys/hash_map.hxx" 00025 00026 namespace itk { 00027 00044 template<class TLabelImage> 00045 class ITK_EXPORT LabelOverlapMeasuresImageFilter : 00046 public ImageToImageFilter<TLabelImage, TLabelImage> 00047 { 00048 public: 00050 typedef LabelOverlapMeasuresImageFilter Self; 00051 typedef ImageToImageFilter<TLabelImage,TLabelImage> Superclass; 00052 typedef SmartPointer<Self> Pointer; 00053 typedef SmartPointer<const Self> ConstPointer; 00054 00056 itkNewMacro( Self ); 00057 00059 itkTypeMacro( LabelOverlapMeasuresImageFilter, ImageToImageFilter ); 00060 00062 typedef TLabelImage LabelImageType; 00063 typedef typename TLabelImage::Pointer LabelImagePointer; 00064 typedef typename TLabelImage::ConstPointer LabelImageConstPointer; 00065 00066 typedef typename TLabelImage::RegionType RegionType; 00067 typedef typename TLabelImage::SizeType SizeType; 00068 typedef typename TLabelImage::IndexType IndexType; 00069 00070 typedef typename TLabelImage::PixelType LabelType; 00071 00073 typedef typename NumericTraits<LabelType>::RealType RealType; 00074 00079 class LabelSetMeasures 00080 { 00081 public: 00082 // default constructor 00083 LabelSetMeasures() 00084 { 00085 m_Source = 0; 00086 m_Target = 0; 00087 m_Union = 0; 00088 m_Intersection = 0; 00089 m_SourceComplement = 0; 00090 m_TargetComplement = 0; 00091 } 00092 00093 // added for completeness 00094 LabelSetMeasures& operator=( const LabelSetMeasures& l ) 00095 { 00096 m_Source = l.m_Source; 00097 m_Target = l.m_Target; 00098 m_Union = l.m_Union; 00099 m_Intersection = l.m_Intersection; 00100 m_SourceComplement = l.m_SourceComplement; 00101 m_TargetComplement = l.m_TargetComplement; 00102 } 00103 00104 unsigned long m_Source; 00105 unsigned long m_Target; 00106 unsigned long m_Union; 00107 unsigned long m_Intersection; 00108 unsigned long m_SourceComplement; 00109 unsigned long m_TargetComplement; 00110 }; 00111 00113 typedef itksys::hash_map<LabelType, LabelSetMeasures> MapType; 00114 typedef typename MapType::iterator MapIterator; 00115 typedef typename MapType::const_iterator MapConstIterator; 00116 00118 itkStaticConstMacro( ImageDimension, unsigned int, 00119 TLabelImage::ImageDimension ); 00120 00122 void SetSourceImage( const LabelImageType * image ) 00123 { this->SetNthInput( 0, const_cast<LabelImageType *>( image ) ); } 00124 00126 void SetTargetImage( const LabelImageType * image ) 00127 { this->SetNthInput( 1, const_cast<LabelImageType *>( image ) ); } 00128 00130 const LabelImageType * GetSourceImage( void ) 00131 { return this->GetInput( 0 ); } 00132 00134 const LabelImageType * GetTargetImage( void ) 00135 { return this->GetInput( 1 ); } 00136 00138 MapType GetLabelSetMeasures() 00139 { return this->m_LabelSetMeasures; } 00140 00146 RealType GetTotalOverlap(); 00147 RealType GetUnionOverlap(); 00148 RealType GetMeanOverlap(); 00149 RealType GetVolumeSimilarity(); 00150 RealType GetFalseNegativeError(); 00151 RealType GetFalsePositiveError(); 00152 00154 RealType GetTargetOverlap( LabelType ); 00155 RealType GetUnionOverlap( LabelType ); 00156 RealType GetMeanOverlap( LabelType ); 00157 RealType GetVolumeSimilarity( LabelType ); 00158 RealType GetFalseNegativeError( LabelType ); 00159 RealType GetFalsePositiveError( LabelType ); 00160 00162 RealType GetJaccardCoefficient() 00163 { return this->GetUnionOverlap(); } 00164 RealType GetJaccardCoefficient( LabelType label ) 00165 { return this->GetUnionOverlap( label ); } 00166 RealType GetDiceCoefficient() 00167 { return this->GetMeanOverlap(); } 00168 RealType GetDiceCoefficient( LabelType label ) 00169 { return this->GetMeanOverlap( label ); } 00171 00172 00173 #ifdef ITK_USE_CONCEPT_CHECKING 00174 00175 itkConceptMacro( Input1HasNumericTraitsCheck, 00176 ( Concept::HasNumericTraits<LabelType> ) ); 00177 00179 #endif 00180 00181 protected: 00182 LabelOverlapMeasuresImageFilter(); 00183 ~LabelOverlapMeasuresImageFilter(){}; 00184 void PrintSelf( std::ostream& os, Indent indent ) const; 00185 00191 void AllocateOutputs(); 00192 00193 void BeforeThreadedGenerateData(); 00194 00195 void AfterThreadedGenerateData(); 00196 00198 void ThreadedGenerateData( const RegionType&, ThreadIdType ); 00199 00200 // Override since the filter needs all the data for the algorithm 00201 void GenerateInputRequestedRegion(); 00202 00203 // Override since the filter produces all of its output 00204 void EnlargeOutputRequestedRegion( DataObject *data ); 00205 00206 private: 00207 LabelOverlapMeasuresImageFilter( const Self& ); //purposely not implemented 00208 void operator=( const Self& ); //purposely not implemented 00209 00210 std::vector<MapType> m_LabelSetMeasuresPerThread; 00211 MapType m_LabelSetMeasures; 00212 }; // end of class 00213 00214 } // end namespace itk 00215 00216 #ifndef ITK_MANUAL_INSTANTIATION 00217 #include "itkLabelOverlapMeasuresImageFilter.hxx" 00218 #endif 00219 00220 #endif 00221