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 #include "cmtkLabelCombinationSTAPLE.h"
00034
00035 namespace
00036 cmtk
00037 {
00038
00041
00042 LabelCombinationSTAPLE::LabelCombinationSTAPLE( const std::vector<TypedArray::SmartPtr>& data, const int maxIterations, const ScalarDataType resultType )
00043 {
00044 const size_t numberOfInputs = data.size();
00045 const size_t numberOfPixels = data[ 0 ]->GetDataSize();
00046 this->m_Result = TypedArray::SmartPtr( TypedArray::Create( resultType, numberOfPixels ) );
00047
00048
00049
00050 float totalSum = 0;
00051 #pragma omp parallel for reduction(+:totalSum)
00052 for ( size_t n = 0; n < numberOfPixels; ++n )
00053 {
00054 Types::DataItem w = 0;
00055 for ( size_t i = 0; i < numberOfInputs; ++i )
00056 {
00057 Types::DataItem value;
00058 if ( data[i]->Get( value, n ) )
00059 {
00060 w += value;
00061 totalSum += value;
00062 }
00063 }
00064 this->m_Result->Set( w / numberOfInputs, n );
00065 }
00066
00067
00068 const float globalPrior = totalSum / (numberOfInputs * numberOfPixels );
00069
00070
00071 this->m_VecP.resize( numberOfInputs );
00072 this->m_VecQ.resize( numberOfInputs );
00073
00074
00075 for ( int it = 0; it < maxIterations; ++it )
00076 {
00077
00078 for ( size_t i = 0; i < numberOfInputs; ++i )
00079 {
00080 this->m_VecP[i] = this->m_VecQ[i] = 0;
00081 }
00082
00083 float sumW = 0;
00084 for ( size_t n = 0; n < numberOfPixels; ++n )
00085 {
00086 Types::DataItem w;
00087 this->m_Result->Get( w, n );
00088 sumW += w;
00089
00090 for ( size_t i = 0; i < numberOfInputs; ++i )
00091 {
00092 Types::DataItem value;
00093 data[i]->Get( value, n );
00094 this->m_VecP[i] += w * value;
00095 this->m_VecQ[i] += (1.0 - w) * (1.0 - value);
00096 }
00097 }
00098
00099 for ( size_t i = 0; i < numberOfInputs; ++i )
00100 {
00101 this->m_VecP[i] /= sumW;
00102 this->m_VecQ[i] /= (numberOfPixels - sumW);
00103 }
00104
00105
00106 #pragma omp parallel for
00107 for ( size_t n = 0; n < numberOfPixels; ++n )
00108 {
00109 float alpha = globalPrior;
00110 float beta = (1.0-globalPrior);
00111
00112 Types::DataItem w = 0;
00113 for ( size_t i = 0; i < numberOfInputs; ++i )
00114 {
00115 if ( data[i]->Get( w, n ) )
00116 {
00117 alpha *= (1-w-m_VecP[i]);
00118 beta *= (w-m_VecQ[i]);
00119 }
00120 }
00121 this->m_Result->Set( alpha / (alpha+beta), n );
00122 }
00123 }
00124 }
00125
00126 }