<br clear="all">Hi All,<br>I'm trying to run the EM algorithm in ITK on my image.<br>My image is a simple scalar 3D volume.<br>I wrote the following code, based on the itkSoftwareGuide example, but it seems that the estimator does not run at all.<br>
The output estimated values are exactly the same as the initialization.<br>Thanks,<br>Moti<br><br><br>*********************************** Begining of code ****************************************************<br> unsigned int numberOfClasses = 2;<br>
typedef itk::Vector< PixelType, 1 > MeasurementVectorType;<br><br> typedef itk::Statistics::ScalarImageToListAdaptor <ImageType> itkScalarImageToListAdaptorType;<br> itkScalarImageToListAdaptorType::Pointer im2list = itkScalarImageToListAdaptorType::New();<br>
im2list->SetImage (sample_volume);<br><br><br><br> typedef itkScalarImageToListAdaptorType SampleType;<br> <br> <br> typedef itk::Array< double > ParametersType;<br> ParametersType params( 2 );<br>
<br> std::vector< ParametersType > initialParameters( numberOfClasses );<br> params[0] = 60;<br> params[1] = 50;<br> initialParameters[0] = params;<br><br> params[0] = 250;<br> params[1] = 50;<br> initialParameters[1] = params;<br>
<br> typedef itk::Statistics::GaussianMixtureModelComponent< SampleType > ComponentType;<br><br> std::vector< ComponentType::Pointer > components;<br> for ( unsigned int i = 0 ; i < numberOfClasses ; i++ )<br>
{<br> components.push_back( ComponentType::New() );<br> (components[i])->SetSample( im2list );<br> (components[i])->SetParameters( initialParameters[i] );<br> }<br><br><br><br> typedef itk::Statistics::ExpectationMaximizationMixtureModelEstimator< SampleType > EstimatorType;<br>
EstimatorType::Pointer estimator = EstimatorType::New();<br> estimator->SetSample( im2list );<br> estimator->SetMaximumIteration( 200 );<br><br> itk::Array< double > initialProportions(numberOfClasses);<br>
initialProportions[0] = 0.5;<br> initialProportions[1] = 0.5;<br><br> estimator->SetInitialProportions( initialProportions );<br> <br> for ( unsigned int i = 0 ; i < numberOfClasses ; i++)<br> {<br>
estimator->AddComponent( (ComponentType::Superclass*)<br> (components[i]).GetPointer() );<br> }<br> <br> estimator->Update();<br> for ( unsigned int i = 0 ; i < numberOfClasses ; i++ )<br>
{<br> std::cout << "Cluster[" << i << "]" << std::endl;<br> std::cout << " Parameters:" << std::endl;<br> std::cout << " " << (components[i])->GetFullParameters() <br>
<< std::endl;<br> std::cout << " Proportion: ";<br> std::cout << " " << (*estimator->GetProportions())[i] << std::endl;<br> }<br>
<br>************************************ end of code **********************************************************<br>-- <br>__<br>Moti Freiman, Ph.D Student.<br>Medical Image Processing and Computer-Assisted Surgery Laboratory.<br>
School of Computer Science and Engineering.<br>The Hebrew University of Jerusalem Givat Ram, Jerusalem 91904, Israel<br>Phone: +(972)-2-658-5371 (laboratory)<br>WWW site: <a href="http://www.cs.huji.ac.il/~freiman">http://www.cs.huji.ac.il/~freiman</a>