[Insight-users] problem solved--- cannot get proper classification using itk:GaussianDensityFunction after EM clustering
Baoyun Li
baoyun_li123 at yahoo.com
Mon Mar 23 09:56:54 EDT 2009
Hi, Luis:
Seems you suggest to fully use ITK framework. Let's say: use itkImagetoSample adapter, get the sample, and perform some kind of clustering (EM or K-means), then using itkImageClassifcation to make decision.
Since I am now using itk, we would like to try my best to follow itk style.
Currently, I am trying to segment brain tumor as while as tissues. Later may goes to MS lesion.
Can you explain more clearly about your comments?
//Whether the lesions can be segmented using EM or not is something
//that depends on the characteristics of the lesions, and the specific
//modalities of MR of your images.
I have multiple mr images, T1,T2,PD, flair. Do you thing those modalities are engough for EM to segment the leision or tumor? I have an impression that clustering algorithm or EM may have trouble to segmenent clusters with small number of voxels since the local minimum can easily lead the clustering algorithm to ignore the cluster with few voxels. In this case, clustering on regigin of interested may help. However, I am trying to develop something with minimum human operation. Maybe my impression is wrong. Please correct me.
However I woule like to give a try
Thanks
Baoyun.
________________________________
From: Luis Ibanez <luis.ibanez at kitware.com>
To: Baoyun Li <baoyun_li123 at yahoo.com>
Cc: insight-users at itk.org
Sent: Saturday, March 21, 2009 12:57:37 PM
Subject: Re: problem solved--- cannot get proper classification using itk:GaussianDensityFunction after EM clustering
Hi Baoyun,
Thanks for the explanation regarding your selection of samples
for the classification.
Your description makes sense, but I'm not sure how well it will
work in practice...
What kind of brain lesions are you trying to segment ?
Whether the lesions can be segmented using EM or not is something
that depends on the characteristics of the lesions, and the specific
modalities of MR of your images.
Are you doing this with multi-components images ?
(e.g. did you take multiple modality images and joined together
in a multi-component image ?). If so, where they registered ?
Regards,
Luis
----------------
Baoyun Li wrote:
> Dear Luis:
> Thanks for your reply and introduce me the new statistic framework.
> /
> /The actual classification code was conditioned to the
> // value of "acumulate1". Why was such thing needed ?
> I have several reasons to condition the classification.
> 1: The input data is skull stripped brain images. So I do not want to use the EM to classifiy the background voxes for saving computation time (please correct me if I am wrong. To me, EM will go though all the voxel, so I believe it will take long time if I tried to classify the background) and also for the performance of accuracy of the EM.
> 2: The lesion or tumor may need other methods to classify before EM. So I give some condition to avoid repeated work on the classified voxels. (One of my senior told me that lesion can not be classified by EM, is that ture?)
> //Indeed, when you are using the Gaussian mixture modeling estimator,
> //the classification stage you should do it by using the
> //itkSampleClassifier class.
> And also I do tried to the itkSampleClassifier for classification. But got same result with I make decision by itkGaussianDensityFunction->Evaluate.. Since both need me to initialize the itkGaussianDensityFunction.. My impression is that I did not set mean and coviarance properly. Althour I print out the mean and covriance by ->GetMean() and ->GetCovariance().
> std::cout << " " <<*(membershipFunctions[i]->GetMean()+0)<< std::endl;
> std::cout << " Gaussian Covariance ";
> std::cout << " " << *(membershipFunctions[i]->GetCovariance()+0) << std::endl;
> After debugging, seems to me that the mean or covirance are actuall given some non-sense number because the pdf I got is extremly small 10^(-7-10). And the CSF class alway have biggest pdf aroun 10^-7 even I forced the measurement vector to be very close (less than 0.5) to mean of other cluster.
> Thanks and my best regards
> Baoyun
>
> ------------------------------------------------------------------------
> *From:* Luis Ibanez <luis.ibanez at kitware.com>
> *To:* Baoyun Li <baoyun_li123 at yahoo.com>
> *Cc:* insight-users at itk.org
> *Sent:* Tuesday, March 17, 2009 5:29:13 PM
> *Subject:* Re: problem solved--- cannot get proper classification using itk:GaussianDensityFunction after EM clustering
>
> Hi Baoyun,
>
> Thanks for letting us know that you found the solution to the problem.
>
> Indeed, when you are using the Gaussian mixture modeling estimator,
> the classification stage you should do it by using the
> itkSampleClassifier class.
>
> The code that you posted in your previous email, is basically what
> the classifier contains inside, but with the added flexibility of
> being reusable and allowing for different types of decision rules.
>
> Looking at your previous code in its current form, it is hard to
> tell what was going wrong.
>
> However, some suspicious elements are:
>
>
> A) OutputPixelType classlabel;
> is uninitialized by the time you start iterating over pixels.
>
> B) The actual classification code was conditioned to the
> value of "acumulate1". Why was such thing needed ?
>
>
> A simple way to find the problem in your code, will be to recompile
> it with a higher settings of warnings (e.g. -Wall if you use gcc).
>
> Chances are that the culprit of the problem is already begin flagged
> out by the compiler.
>
>
> BTW: You may find interesting to start using the new Statistics
> Framework, that is available at:
>
> http://www.na-mic.org/svn/NAMICSandBox/trunk/ITKStatisticsPipelineRefactoring/
>
> You will find a description of what was changed (and why)
> in the following wiki pages:
>
> http://www..itk.org/Wiki/Proposals:Refactoring_Statistics_Framework_2007
>
>
>
>
> Regards,
>
>
> Luis
>
>
> ------------------
> Baoyun Li wrote:
> > Dear All:
> > I just figure out the problem. I need to use itk::GaussianMixtureModelComponent->Evaluate to make decision. The result is ok.
> > but i am still not clear what happened if I used itk::GaussianDensityFunction->Evaluate() to get decision. Maybe I did not use it properly. Still interested to know what happened.
> > Can somebody tell me whether my code is wrong or I did not used itk::GaussianDensityFunction->Evaluate() properly?
> > Thanks
> > Baoyun
> >
> > ------------------------------------------------------------------------
> > *From:* Baoyun Li <baoyun_li123 at yahoo.com <mailto:baoyun_li123 at yahoo.com>>
> > *To:* Luis Ibanez <luis.ibanez at kitware.com <mailto:luis.ibanez at kitware.com>>
> > *Cc:* insight-users at itk.org <mailto:insight-users at itk.org>
> > *Sent:* Tuesday, March 17, 2009 12:24:04 PM
> > *Subject:* cannot get proper classification using itk:GaussianDensityFunction after EM clustering
> >
> > Dear ALL:
> > I am using EM gassian mixutrue estimator to estimate the mean and covariance of vector image. I first adapt the image to sample, and the EM works well.
> > It produced mean value for Gray matter , whithe matter and CSF, the mean value looks ok to me.
> > But when I try to assign the label to the image, I cannot get the proper labled image. I got the estimated all the voxle to the one class. And the pdf of GassianDensityFunction always have the biggest value for CSF, that should not happend.
> > Below is part of my code.
> > 1, I first get the pararameter of each component by : finalparameters=(components[i])->GetFullParameters();
> > 2, Then I decompose the parameters to estimatedmean and estimatedcovariance
> > 3, set the mean for GaussianDensityFunction by : membershipFunctions[i]->SetMean(&estimatedmean );
> > membershipFunctions[i]->SetCovariance( &estimatedcovariance);
> > 4, In the lableing program, I used eveluateresult[i]=(membershipFunctions[i]->Evaluate(mv)) to get pdf for each class, mv is the measurement vector obtained of images by itk iterator
> > 5, then I find the class with biggest pdf, assign the label .
> > The code is listed below, can some body help me to find what is wrong.
> > Thanks
> > Baoyun
> > ///////give the mean value and covariance to GaussianDensityFunction typedef itk::Statistics::GaussianDensityFunction<ComponentType::MeasurementVectorType > MembershipFunctionType;
> > std::vector< MembershipFunctionType::Pointer > membershipFunctions(numberOfClasses);
> > unsigned int paramIndex;
> > ParametersType finalparameters((NumberOfComponents+1)*NumberOfComponents);
> > typedef MembershipFunctionType::MeanType MeanType;
> > typedef MembershipFunctionType::CovarianceType CovarianceType;
> > MeanType estimatedmean(NumberOfComponents);
> > CovarianceType estimatedcovariance;
> > typedef ComponentType::MeasurementVectorSizeType MeasurementVectorSizeType;
> > MeasurementVectorSizeType measurementVectorSize=NumberOfComponents;
> > estimatedcovariance.SetSize( measurementVectorSize, measurementVectorSize );
> > //estimatedmean..SetSize( measurementVectorSize, 1);
> > // estimatedmean.Fill(0.0) ;
> > for ( unsigned int i = 0 ; i < numberOfClasses ; i++ )
> > {
> > // membershipFunctions.push_back(MembershipFunctionType::New());
> > membershipFunctions[i]=MembershipFunctionType::New();
> > std::cout << " Size of Gaussian : ";
> > std::cout << " " << (membershipFunctions[i])->GetMeasurementVectorSize() << std::endl;
> > finalparameters=(components[i])->GetFullParameters();
> > paramIndex=0; for (unsigned int i1 = 0 ; i1 < measurementVectorSize ; i1++)
> > {
> > estimatedmean[i1] = finalparameters[paramIndex] ;
> > ++paramIndex ;
> > }
> > for (unsigned int i1 = 0 ; i1 < measurementVectorSize ; i1++ )
> > {
> > for (unsigned int j1 = 0 ; j1 < measurementVectorSize; j1++ )
> > {
> > estimatedcovariance.GetVnlMatrix()..put(i1, j1, finalparameters[paramIndex]) ;
> > ++paramIndex ;
> > }
> > }
> > // finalProportions[i]=(*estimator->GetProportions())[i];
> > std::cout << "********************************" << std::endl;
> > std::cout << "class[" << i << "]" << std::endl;
> > std::cout << " Estimated Mean:" << std::endl;
> > std::cout << " " << estimatedmean
> > << std::endl;
> > std::cout << " Estimated Covariance ";
> > std::cout << " " << estimatedcovariance << std::endl;
> > membershipFunctions[i]->SetMean(&estimatedmean );
> > membershipFunctions[i]->SetCovariance( &estimatedcovariance);
> > std::cout << "***************************" << std::endl;
> > std::cout << "class[" << i << "]" << std::endl;
> > std::cout << " Gaussain Mean:" << std::endl;
> > std::cout << " " <<*(membershipFunctions[i]->GetMean()+0)<< std::endl;
> > // std::cout << " " <<*(membershipFunctions[i]->GetMean()+1)<< std::endl;
> > std::cout << " Gaussian Covariance ";
> > std::cout << " " << *(membershipFunctions[i]->GetCovariance()+0) << std::endl;
> > // std::cout << " " << *(membershipFunctions[i]->GetCovariance()+1) << std::endl;
> > // std::cout << " " << *(membershipFunctions[i]->GetCovariance()+3) << std::endl;
> > }
> > /////to lable the image typedef unsigned char OutputPixelType;
> > typedef itk::Image< OutputPixelType, 3 > OutputImageType;
> > OutputImageType::Pointer outputPtr=reader1->GetOutput();
> > typedef itk::ImageRegionIterator< OutputImageType > ImageIterator;
> > typedef VectorImageType::RegionType RegionType;
> > RegionType region = outputPtr->GetBufferedRegion();
> > //
> > // ImageIterator pixel( outputPtr, region );
> > typedef itk::Vector< double, numberOfClasses > EvaluationVectorType;
> > EvaluationVectorType eveluateresult;
> > //pixel.GoToBegin();
> > // itk::Array< double > finalProportions(numberOfClasses);
> > for(unsigned char i=0;i<numberOfClasses;i++)
> > {
> > finalProportions[i]=(*estimator->GetProportions())[i];
> > }
> > double maxvalue;
> > OutputPixelType classlabel;
> > for ( pixel.GoToBegin(),constIterator.GoToBegin(); !pixel.IsAtEnd(); ++pixel,++constIterator )
> > {
> > mv=constIterator.Get();
> > accumulate1=0;
> > maxvalue=0;
> > for( unsigned int i=0;i<NumberOfComponents;i++)
> > {
> > accumulate1=accumulate1+mv[i];
> > }
> > if(accumulate1>20)
> > {
> > for(unsigned char i=0;i<numberOfClasses;i++)
> > {
> > eveluateresult[i]=(membershipFunctions[i]->Evaluate(mv))*finalProportions[i];
> > }
> > for(unsigned char i=0;i<numberOfClasses;i++)
> > {
> > if(eveluateresult[i]>=maxvalue)
> > {
> > maxvalue=eveluateresult[i];
> > classlabel=i+1;
> > }
> > // if(mv[0]==94&&mv[1]==77)
> > // {
> > // std::cout << "evaluation result" << eveluateresult << "]" << std::endl;
> > // }
> > }
> > pixel.Set(classlabel);
> > }
> > else
> > {
> > pixel.Set(0);
> > }
> > }
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090323/0a5a1391/attachment-0001.htm>
More information about the Insight-users
mailing list