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