6 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
9 this->SetNthInput(0, const_cast<TMaskImage*>(mask));
12 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
15 this->SetNthInput(1, const_cast<TInputImage*>(image));
16 m_ImagesVector.push_back(image);
19 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
22 this->SetNthInput(2, const_cast<TInputImage*>(image));
23 m_ImagesVector.push_back(image);
26 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
29 this->SetNthInput(3, const_cast<TInputImage*>(image));
30 m_ImagesVector.push_back(image);
33 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
36 this->SetNthInput(4, const_cast<TAtlasImage*>(image));
37 m_AtlasVector.push_back(image);
40 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
43 this->SetNthInput(5, const_cast<TAtlasImage*>(image));
44 m_AtlasVector.push_back(image);
47 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
50 this->SetNthInput(6, const_cast<TAtlasImage*>(image));
51 m_AtlasVector.push_back(image);
55 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
58 return static_cast< const TMaskImage *
> 59 ( this->itk::ProcessObject::GetInput(0) );
62 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
65 return static_cast< const TInputImage *
> 66 ( this->itk::ProcessObject::GetInput(1) );
69 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
72 return static_cast< const TInputImage *
> 73 ( this->itk::ProcessObject::GetInput(2) );
76 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
79 return static_cast< const TInputImage *
> 80 ( this->itk::ProcessObject::GetInput(3) );
83 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
86 return static_cast< const TAtlasImage *
> 87 ( this->itk::ProcessObject::GetInput(4) );
90 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
93 return static_cast< const TAtlasImage *
> 94 ( this->itk::ProcessObject::GetInput(5) );
97 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
100 return static_cast< const TAtlasImage *
> 101 ( this->itk::ProcessObject::GetInput(6) );
106 template <
typename TInputImage,
typename TMaskImage,
typename TAtlasImage>
109 const unsigned int numberOfClasses = m_ImagesVector.size();
114 std::vector<InputConstIteratorType> ImagesVectorVectorIt;
115 for (
unsigned int i = 0; i < numberOfClasses; i++ )
118 ImagesVectorVectorIt.push_back(It);
121 std::vector<AtlasConstIteratorType> AtlasVectorVectorIt;
122 for (
unsigned int i = 0; i < numberOfClasses; i++ )
125 AtlasVectorVectorIt.push_back(It);
128 std::vector<GaussianFunctionType::MeanVectorType> means(numberOfClasses,GaussianFunctionType::MeanVectorType( numberOfClasses ));
131 m_Alphas.resize(numberOfClasses,0);
134 for(
unsigned int c = 0; c < numberOfClasses; c++)
136 for(
unsigned int i = 0; i < numberOfClasses; i++)
139 for(
unsigned int j = 0; j < numberOfClasses; j++)
140 covariances[c](i,j) = 0.0;
146 for (
unsigned int k = 0; k < numberOfClasses; k++ )
148 AtlasVectorVectorIt[k].GoToBegin();
149 ImagesVectorVectorIt[k].GoToBegin();
152 while(!MaskIt.IsAtEnd())
154 if ( MaskIt.Get() != 0 )
156 for(
unsigned int c = 0; c < numberOfClasses; c++)
159 m_Alphas[c]+=
static_cast<double>(AtlasVectorVectorIt[c].Get());
162 for(
unsigned int m = 0; m < numberOfClasses; m++)
164 (means[c])[m] += AtlasVectorVectorIt[c].Get() * ImagesVectorVectorIt[m].Get();
169 for (
unsigned int k = 0; k < numberOfClasses; k++ )
171 ++AtlasVectorVectorIt[k];
172 ++ImagesVectorVectorIt[k];
177 for(
unsigned int c = 0; c < numberOfClasses; c++)
179 for(
unsigned int m = 0; m < numberOfClasses; m++)
181 (means[c])[m]/=m_Alphas[c];
188 for (
unsigned int i = 0; i < numberOfClasses; i++ )
190 ImagesVectorVectorIt[i].GoToBegin();
191 AtlasVectorVectorIt[i].GoToBegin();
200 while(!MaskIt.IsAtEnd())
202 if ( MaskIt.Get() != 0 )
204 for(
unsigned int c = 0; c < numberOfClasses; c++)
206 for(
unsigned int m = 0; m < numberOfClasses; m++)
208 x(m,0) = ImagesVectorVectorIt[m].Get();
210 meanT(0,m) = (means[c])[m];
211 meanTTrans(m,0) = (means[c])[m];
213 covariances[c] += ( (x-meanTTrans) * (xT-meanT) ) * (static_cast<double>(AtlasVectorVectorIt[c].Get()) );
217 for (
unsigned int i = 0; i < numberOfClasses; i++ )
219 ++ImagesVectorVectorIt[i];
220 ++AtlasVectorVectorIt[i];
226 for(
unsigned int c = 0; c < numberOfClasses; c++)
229 for(
unsigned int m = 0; m < numberOfClasses; m++)
231 for(
unsigned int n = 0; n < numberOfClasses; n++)
233 covariances[c](m,n) /= m_Alphas[c];
239 for(
unsigned int c = 0; c < numberOfClasses; c++)
244 for(
unsigned int c = 0; c < numberOfClasses; c++)
246 GaussianFunctionType::Pointer gaussian = GaussianFunctionType::New();
247 gaussian->SetMean(means[c]);
248 gaussian->SetCovariance(covariances[c]);
249 m_GaussianModel.push_back(gaussian);
void SetAtlasImage2(const TAtlasImage *image)
TInputImage::ConstPointer GetInputImage3()
void SetAtlasImage1(const TAtlasImage *image)
TInputImage::ConstPointer GetInputImage1()
void SetMask(const TMaskImage *mask)
void Update() ITK_OVERRIDE
calculate parameters of gaussians from images with the probability of the different classes [csf] [gm...
void SetInputImage1(const TInputImage *image)
void SetInputImage2(const TInputImage *image)
TMaskImage::ConstPointer GetMask()
itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType
void SetInputImage3(const TInputImage *image)
TAtlasImage::ConstPointer GetAtlasImage3()
TAtlasImage::ConstPointer GetAtlasImage2()
void SetAtlasImage3(const TAtlasImage *image)
TInputImage::ConstPointer GetInputImage2()
itk::ImageRegionConstIterator< AtlasImageType > AtlasConstIteratorType
TAtlasImage::ConstPointer GetAtlasImage1()
itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType
itk::VariableSizeMatrix< NumericType > DoubleVariableSizeMatrixType