8 template <
typename TInput,
typename TMask,
typename TOutput>
11 this->SetNthInput(0, const_cast<TInput*>(image));
12 m_ImagesVector.push_back(image);
15 template <
typename TInput,
typename TMask,
typename TOutput>
18 this->SetNthInput(1, const_cast<TMask*>(mask));
21 template <
typename TInput,
typename TMask,
typename TOutput>
24 this->SetNthInput(m_NbInputs, const_cast<TInput*>(image));
25 m_IndexImage2 = m_NbInputs;
26 m_ImagesVector.push_back(image);
30 template <
typename TInput,
typename TMask,
typename TOutput>
33 this->SetNthInput(m_NbInputs, const_cast<TInput*>(image));
34 m_IndexImage3 = m_NbInputs;
35 m_ImagesVector.push_back(image);
38 template <
typename TInput,
typename TMask,
typename TOutput>
41 this->SetNthInput(m_NbInputs, const_cast<TInput*>(image));
42 m_IndexImage4 = m_NbInputs;
43 m_ImagesVector.push_back(image);
47 template <
typename TInput,
typename TMask,
typename TOutput>
50 this->SetNthInput(m_NbInputs, const_cast<TInput*>(image));
51 m_IndexImage5 = m_NbInputs;
52 m_ImagesVector.push_back(image);
58 template <
typename TInput,
typename TMask,
typename TOutput>
61 return static_cast< const TInput *
> 62 ( this->itk::ProcessObject::GetInput(0) );
65 template <
typename TInput,
typename TMask,
typename TOutput>
68 return static_cast< const TMask *
> 69 ( this->itk::ProcessObject::GetInput(1) );
72 template <
typename TInput,
typename TMask,
typename TOutput>
75 return static_cast< const TInput *
> 76 ( this->itk::ProcessObject::GetInput(m_IndexImage2) );
79 template <
typename TInput,
typename TMask,
typename TOutput>
82 return static_cast< const TInput *
> 83 ( this->itk::ProcessObject::GetInput(m_IndexImage3) );
86 template <
typename TInput,
typename TMask,
typename TOutput>
89 return static_cast< const TInput *
> 90 ( this->itk::ProcessObject::GetInput(m_IndexImage4) );
93 template <
typename TInput,
typename TMask,
typename TOutput>
96 return static_cast< const TInput *
> 97 ( this->itk::ProcessObject::GetInput(m_IndexImage5) );
100 template <
typename TInput,
typename TMask,
typename TOutput>
104 if( m_OutputFilename !=
"" )
106 std::cout <<
"Writing classification image to: " << m_OutputFilename << std::endl;
107 anima::writeImage<TOutput>(m_OutputFilename, this->GetOutput());
111 template <
typename TInput,
typename TMask,
typename TOutput>
119 std::vector<InputConstIteratorType > inputVectorIt;
120 for (
unsigned int i = 0; i < m_ImagesVector.size(); i++ )
123 inputVectorIt.push_back(It);
126 while(!classificationIt.IsAtEnd())
128 classificationIt.Set(0);
129 if ( maskIt.Get() != 0 )
133 for (
unsigned int i = 0; i < inputVectorIt.size(); i++ )
135 intensities( i,0 ) = inputVectorIt[ i ].Get();
138 double maxProbability = -1.0;
139 int maxProbaIndex = -1;
140 for (
unsigned int i = 0; i < m_GaussianModel.size(); i++ )
142 double proba = m_Alphas[i] * this->probability( intensities, m_GaussianModel[i] );
143 if ( maxProbability < proba )
145 maxProbability = proba;
149 if ( maxProbaIndex > 0 )
151 classificationIt.Set(maxProbaIndex);
155 classificationIt.Set(m_GaussianModel.size()+1);
160 for (
unsigned int i = 0; i < m_ImagesVector.size(); i++ )
169 template <
typename TInput,
typename TMask,
typename TOutput>
174 sigma = model->GetCovariance();
176 GaussianFunctionType::MeanVectorType muVect = model->GetMean();
177 mu.SetSize(muVect.Size(),1);
178 for(
unsigned int j = 0; j < muVect.Size(); j++)
183 double down =
static_cast<double>(std::sqrt( std::pow(2*M_PI,muVect.Size()) * std::abs( vnl_determinant(sigma.GetVnlMatrix())) ));
184 distance = point - mu;
185 distanceT = distance.GetTranspose();
186 value = distanceT * (sigma.GetInverse() * distance.GetVnlMatrix());
188 if(value(0,0) != value(0,0))
191 double exponent =- 0.5* value(0,0);
192 return exp(exponent)/down;
itk::VariableSizeMatrix< NumericType > DoubleVariableSizeMatrixType
double probability(DoubleVariableSizeMatrixType &point, GaussianFunctionType::Pointer model)
void SetInputImage5(const TInput *image)
TInput::ConstPointer GetInputImage3()
TInput::ConstPointer GetInputImage2()
Superclass::OutputImageRegionType OutputImageRegionType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE
void SetInputImage4(const TInput *image)
void SetMask(const TMask *mask)
void SetInputImage2(const TInput *image)
itk::ImageRegionConstIterator< TMask > MaskConstIteratorType
TInput::ConstPointer GetInputImage4()
itk::ImageRegionIterator< TOutput > OutputIteratorType
TInput::ConstPointer GetInputImage5()
TMask::ConstPointer GetMask()
void SetInputImage1(const TInput *image)
void SetInputImage3(const TInput *image)
Classify each voxels into one of the given GMM classes.
itk::ImageRegionConstIterator< TInput > InputConstIteratorType
TInput::ConstPointer GetInputImage1()