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 __itkVectorThresholdSegmentationLevelSetFunction_h 00019 #define __itkVectorThresholdSegmentationLevelSetFunction_h 00020 00021 #include "itkSegmentationLevelSetFunction.h" 00022 #include "itkNumericTraits.h" 00023 #include "itkMahalanobisDistanceMembershipFunction.h" 00024 namespace itk 00025 { 00057 template< class TImageType, class TFeatureImageType > 00058 class ITK_EXPORT VectorThresholdSegmentationLevelSetFunction: 00059 public SegmentationLevelSetFunction< TImageType, TFeatureImageType > 00060 { 00061 public: 00063 typedef VectorThresholdSegmentationLevelSetFunction Self; 00064 typedef SegmentationLevelSetFunction< TImageType, TFeatureImageType > 00065 Superclass; 00066 typedef SmartPointer< Self > Pointer; 00067 typedef SmartPointer< const Self > ConstPointer; 00068 typedef TFeatureImageType FeatureImageType; 00069 00071 itkNewMacro(Self); 00072 00074 itkTypeMacro(VectorThresholdSegmentationLevelSetFunction, SegmentationLevelSetFunction); 00075 00077 typedef typename Superclass::ImageType ImageType; 00078 typedef typename Superclass::ScalarValueType ScalarValueType; 00079 typedef typename Superclass::FeatureScalarType FeatureScalarType; 00080 typedef typename Superclass::RadiusType RadiusType; 00081 00083 itkStaticConstMacro(ImageDimension, unsigned int, 00084 Superclass::ImageDimension); 00085 00087 typedef typename FeatureImageType::PixelType FeatureImagePixelType; 00088 itkStaticConstMacro(NumberOfComponents, unsigned int, 00089 FeatureImagePixelType::Dimension); 00090 00091 typedef Statistics::MahalanobisDistanceMembershipFunction< FeatureScalarType > MahalanobisFunctionType; 00092 typedef typename MahalanobisFunctionType::Pointer MahalanobisFunctionPointer; 00093 typedef typename MahalanobisFunctionType::MeanVectorType MeanVectorType; 00094 typedef typename MahalanobisFunctionType::CovarianceMatrixType CovarianceMatrixType; 00095 00097 void SetMean(const MeanVectorType & mean) { m_Mahalanobis->SetMean(mean); } 00098 const MeanVectorType & GetMean() const { return m_Mahalanobis->GetMean(); } 00100 00101 void SetCovariance(const CovarianceMatrixType & cov) { m_Mahalanobis->SetCovariance(cov); } 00102 const CovarianceMatrixType & GetCovariance() const { return m_Mahalanobis->GetCovariance(); } 00103 00105 void SetThreshold(ScalarValueType thr) 00106 { 00107 m_Threshold = thr; 00108 } 00109 00110 ScalarValueType GetThreshold() 00111 { 00112 return m_Threshold; 00113 } 00114 00115 virtual void CalculateSpeedImage(); 00116 00117 virtual void Initialize(const RadiusType & r) 00118 { 00119 Superclass::Initialize(r); 00120 00121 this->SetAdvectionWeight(NumericTraits< ScalarValueType >::Zero); 00122 this->SetPropagationWeight(-1.0 * NumericTraits< ScalarValueType >::One); 00123 this->SetCurvatureWeight(NumericTraits< ScalarValueType >::One); 00124 } 00125 00126 protected: 00127 VectorThresholdSegmentationLevelSetFunction() 00128 { 00129 MeanVectorType mean(NumberOfComponents); 00130 CovarianceMatrixType covariance(NumberOfComponents, NumberOfComponents); 00131 00132 mean.Fill(NumericTraits< typename FeatureScalarType::ValueType >::Zero); 00133 covariance.Fill(NumericTraits< typename FeatureScalarType::ValueType >::Zero); 00134 00135 m_Mahalanobis = MahalanobisFunctionType::New(); 00136 m_Mahalanobis->SetMean(mean); 00137 m_Mahalanobis->SetCovariance(covariance); 00138 00139 this->SetAdvectionWeight(0.0); 00140 this->SetPropagationWeight(1.0); 00141 this->SetThreshold(1.8); 00142 } 00143 00144 virtual ~VectorThresholdSegmentationLevelSetFunction(){} 00145 00146 VectorThresholdSegmentationLevelSetFunction(const Self &); //purposely not 00147 // implemented 00148 void operator=(const Self &); //purposely not 00149 00150 // implemented 00151 00152 void PrintSelf(std::ostream & os, Indent indent) const 00153 { 00154 Superclass::PrintSelf(os, indent); 00155 os << indent << "MahalanobisFunction: " << m_Mahalanobis << std::endl; 00156 os << indent << "ThresholdValue: " << m_Threshold << std::endl; 00157 } 00158 00159 MahalanobisFunctionPointer m_Mahalanobis; 00160 ScalarValueType m_Threshold; 00161 }; 00162 } // end namespace itk 00163 00164 #ifndef ITK_MANUAL_INSTANTIATION 00165 #include "itkVectorThresholdSegmentationLevelSetFunction.hxx" 00166 #endif 00167 00168 #endif 00169