Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __cmtkEntropyMinimizationIntensityCorrectionFunctional_h_included_
00034 #define __cmtkEntropyMinimizationIntensityCorrectionFunctional_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #include <Segmentation/cmtkEntropyMinimizationIntensityCorrectionFunctionalBase.h>
00039
00040 #include <Base/cmtkPolynomial.h>
00041 #include <Base/cmtkUniformVolume.h>
00042 #include <Base/cmtkDataGrid.h>
00043
00044 #include <System/cmtkThreadPool.h>
00045 #include <System/cmtkSmartPtr.h>
00046
00047 namespace
00048 cmtk
00049 {
00050
00055 template<unsigned int NOrderAdd,unsigned int NOrderMul>
00056 class EntropyMinimizationIntensityCorrectionFunctional :
00058 public EntropyMinimizationIntensityCorrectionFunctionalBase
00059 {
00060 public:
00062 typedef EntropyMinimizationIntensityCorrectionFunctional<NOrderAdd,NOrderMul> Self;
00063
00065 typedef SmartPointer<Self> SmartPtr;
00066
00068 typedef EntropyMinimizationIntensityCorrectionFunctionalBase Superclass;
00069
00071 typedef Polynomial<NOrderAdd,Types::Coordinate> PolynomialTypeAdd;
00072
00074 typedef Polynomial<NOrderMul,Types::Coordinate> PolynomialTypeMul;
00075
00077 EntropyMinimizationIntensityCorrectionFunctional()
00078 {
00079 this->m_ParameterVector.SetDim( this->ParamVectorDim() );
00080 this->m_ParameterVector.SetAll( 0.0 );
00081
00082 ThreadPool& threadPool = ThreadPool::GetGlobalThreadPool();
00083 this->m_NumberOfThreads = threadPool.GetNumberOfThreads();
00084 this->m_MonomialsPerThread = std::max( (int)PolynomialTypeAdd::NumberOfMonomials, (int)PolynomialTypeMul::NumberOfMonomials );
00085 this->m_MonomialsVec = Memory::AllocateArray<Types::Coordinate>( this->m_NumberOfThreads * this->m_MonomialsPerThread );
00086 }
00087
00089 virtual ~EntropyMinimizationIntensityCorrectionFunctional()
00090 {
00091 Memory::DeleteArray( this->m_MonomialsVec );
00092 }
00093
00095 static const size_t m_NumberOfParameters = PolynomialTypeAdd::NumberOfMonomials + PolynomialTypeMul::NumberOfMonomials;
00096
00098 virtual size_t ParamVectorDim() const
00099 {
00100 return this->m_NumberOfParameters;
00101 }
00102
00104 #pragma GCC diagnostic ignored "-Wtype-limits"
00105 virtual Types::Coordinate GetParamStep( const size_t idx, const Types::Coordinate mmStep = 1 ) const
00106 {
00107 if ( idx < PolynomialTypeAdd::NumberOfMonomials )
00108 return (this->m_InputImageRange / 256) * this->m_StepSizeAdd[idx] * mmStep;
00109 else
00110 return (this->m_InputImageRange / 256) * this->m_StepSizeMul[idx-PolynomialTypeAdd::NumberOfMonomials] * mmStep;
00111 }
00112
00114 virtual size_t GetNumberOfMonomialsAdd() const
00115 {
00116 return PolynomialTypeAdd::NumberOfMonomials;
00117 }
00118
00120 virtual size_t GetNumberOfMonomialsMul() const
00121 {
00122 return PolynomialTypeMul::NumberOfMonomials;
00123 }
00124
00126 virtual void SetParamVector( CoordinateVector& v )
00127 {
00128 this->m_ParameterVector = v;
00129 for ( int i = 0; i < PolynomialTypeAdd::NumberOfMonomials; ++i )
00130 this->m_CoefficientsAdd[i] = v[i] * this->m_MulCorrectionAdd[i];
00131
00132 size_t ofs = PolynomialTypeAdd::NumberOfMonomials;
00133 for ( int i = 0; i < PolynomialTypeMul::NumberOfMonomials; ++i, ++ofs )
00134 this->m_CoefficientsMul[i] = v[ofs] * this->m_MulCorrectionMul[i];
00135 }
00136
00138 virtual void GetParamVector( CoordinateVector& v )
00139 {
00140 v = this->m_ParameterVector;
00141 }
00142
00147 virtual typename Self::ReturnType EvaluateWithGradient( CoordinateVector& v, CoordinateVector& g, const Types::Coordinate step );
00148
00149 protected:
00151 CoordinateVector m_ParameterVector;
00152
00154 Types::Coordinate m_StepSizeAdd[1+PolynomialTypeAdd::NumberOfMonomials];
00155
00157 Types::Coordinate m_StepSizeMul[1+PolynomialTypeMul::NumberOfMonomials];
00158
00160 Types::Coordinate m_CoefficientsAdd[1+PolynomialTypeAdd::NumberOfMonomials];
00161
00163 Types::Coordinate m_CoefficientsMul[1+PolynomialTypeMul::NumberOfMonomials];
00164
00166 Types::Coordinate m_AddCorrectionAdd[1+PolynomialTypeAdd::NumberOfMonomials];
00167
00169 Types::Coordinate m_MulCorrectionAdd[1+PolynomialTypeAdd::NumberOfMonomials];
00170
00172 Types::Coordinate m_AddCorrectionMul[1+PolynomialTypeMul::NumberOfMonomials];
00173
00175 Types::Coordinate m_MulCorrectionMul[1+PolynomialTypeMul::NumberOfMonomials];
00176
00177 private:
00184 size_t m_NumberOfThreads;
00185
00187 size_t m_MonomialsPerThread;
00188
00190 Types::Coordinate* m_MonomialsVec;
00191
00193 virtual void UpdateCorrectionFactors();
00194
00196 virtual void UpdateBiasFields( const bool foregroundOnly = true );
00197
00199 static void UpdateBiasFieldsThreadFunc( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00200
00202 static void UpdateBiasFieldsAllThreadFunc( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00203
00205 virtual void UpdateBiasFieldAdd( const bool foregroundOnly = true );
00206
00208 static void UpdateBiasFieldAddThreadFunc( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00209
00211 static void UpdateBiasFieldAddAllThreadFunc( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00212
00214 virtual void UpdateBiasFieldMul( const bool foregroundOnly = true );
00215
00217 static void UpdateBiasFieldMulThreadFunc( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00218
00220 static void UpdateBiasFieldMulAllThreadFunc( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00221 };
00222
00224 template<unsigned int NDegreeMul>
00225 EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr
00226 CreateEntropyMinimizationIntensityCorrectionFunctional
00227 ( const unsigned int polynomialDegreeAdd );
00228
00230 EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr
00231 CreateEntropyMinimizationIntensityCorrectionFunctional
00232 ( const unsigned int polynomialDegreeAdd, const unsigned int polynomialDegreeMul );
00233
00239 EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr
00240 CreateEntropyMinimizationIntensityCorrectionFunctional
00241 ( const unsigned int polynomialDegreeAdd, const unsigned int polynomialDegreeMul,
00242 EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr oldFunctional );
00243
00245
00246 }
00247
00248 #include "cmtkEntropyMinimizationIntensityCorrectionFunctional.txx"
00249
00250 #endif // #ifndef __cmtkEntropyMinimizationIntensityCorrectionFunctional_h_included_
00251