<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>Hi, Luis:</DIV>
<DIV> </DIV>
<DIV>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.</DIV>
<DIV> </DIV>
<DIV>Since I am now using itk, we would like to try my best to follow itk style.</DIV>
<DIV> </DIV>
<DIV>Currently, I am trying to segment brain tumor as while as tissues. Later may goes to MS lesion.</DIV>
<DIV> </DIV>
<DIV>Can you explain more clearly about your comments?</DIV>
<DIV> </DIV>
<DIV>//Whether the lesions can be segmented using EM or not is something<BR>//that depends on the characteristics of the lesions, and the specific<BR>//modalities of MR of your images.</DIV>
<DIV> </DIV>
<DIV>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.</DIV>
<DIV> </DIV>
<DIV>However I woule like to give a try</DIV>
<DIV> </DIV>
<DIV>Thanks</DIV>
<DIV> </DIV>
<DIV>Baoyun.<BR><BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face=Tahoma size=2>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Luis Ibanez <luis.ibanez@kitware.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Baoyun Li <baoyun_li123@yahoo.com><BR><B><SPAN style="FONT-WEIGHT: bold">Cc:</SPAN></B> insight-users@itk.org<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Saturday, March 21, 2009 12:57:37 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: problem solved--- cannot get proper classification using itk:GaussianDensityFunction after EM clustering<BR></FONT><BR><BR>Hi Baoyun,<BR><BR>Thanks for the explanation regarding your selection of samples<BR>for the classification.<BR><BR>Your description makes sense, but I'm not sure how well it will<BR>work in practice...<BR><BR>What kind of brain lesions are you trying to segment ?<BR><BR>Whether the lesions can be segmented using EM or not is something<BR>that depends on the characteristics of the lesions, and the specific<BR>modalities of
MR of your images.<BR><BR>Are you doing this with multi-components images ?<BR>(e.g. did you take multiple modality images and joined together<BR>in a multi-component image ?). If so, where they registered ?<BR><BR><BR><BR> Regards,<BR><BR><BR> Luis<BR><BR><BR><BR>----------------<BR>Baoyun Li wrote:<BR>> Dear Luis:<BR>> Thanks for your reply and introduce me the new statistic framework.<BR>> /<BR>> /The actual classification code was conditioned to the<BR>> // value of "acumulate1". Why was such thing needed ?<BR>> I have several reasons to condition the classification.<BR>> 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.<BR>> 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?)<BR>> //Indeed, when you are using the Gaussian mixture modeling estimator,<BR>> //the classification stage you should do it by using the<BR>> //itkSampleClassifier class.<BR>> 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().<BR>> std::cout << " "
<<*(membershipFunctions[i]->GetMean()+0)<< std::endl;<BR>> std::cout << " Gaussian Covariance ";<BR>> std::cout << " " << *(membershipFunctions[i]->GetCovariance()+0) << std::endl;<BR>> 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.<BR>> Thanks and my best regards<BR>> Baoyun<BR>> <BR>> ------------------------------------------------------------------------<BR>> *From:* Luis Ibanez <<A href="mailto:luis.ibanez@kitware.com" ymailto="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</A>><BR>> *To:* Baoyun Li <<A
href="mailto:baoyun_li123@yahoo.com" ymailto="mailto:baoyun_li123@yahoo.com">baoyun_li123@yahoo.com</A>><BR>> *Cc:* <A href="mailto:insight-users@itk.org" ymailto="mailto:insight-users@itk.org">insight-users@itk.org</A><BR>> *Sent:* Tuesday, March 17, 2009 5:29:13 PM<BR>> *Subject:* Re: problem solved--- cannot get proper classification using itk:GaussianDensityFunction after EM clustering<BR>> <BR>> Hi Baoyun,<BR>> <BR>> Thanks for letting us know that you found the solution to the problem.<BR>> <BR>> Indeed, when you are using the Gaussian mixture modeling estimator,<BR>> the classification stage you should do it by using the<BR>> itkSampleClassifier class.<BR>> <BR>> The code that you posted in your previous email, is basically what<BR>> the classifier contains inside, but with the added flexibility of<BR>> being reusable and allowing for different types of decision rules.<BR>> <BR>> Looking at
your previous code in its current form, it is hard to<BR>> tell what was going wrong.<BR>> <BR>> However, some suspicious elements are:<BR>> <BR>> <BR>> A) OutputPixelType classlabel;<BR>> is uninitialized by the time you start iterating over pixels.<BR>> <BR>> B) The actual classification code was conditioned to the<BR>> value of "acumulate1". Why was such thing needed ?<BR>> <BR>> <BR>> A simple way to find the problem in your code, will be to recompile<BR>> it with a higher settings of warnings (e.g. -Wall if you use gcc).<BR>> <BR>> Chances are that the culprit of the problem is already begin flagged<BR>> out by the compiler.<BR>> <BR>> <BR>> BTW: You may find interesting to start using the new Statistics<BR>> Framework, that is available at:<BR>> <BR>>
http://www.na-mic.org/svn/NAMICSandBox/trunk/ITKStatisticsPipelineRefactoring/<BR>> <BR>> You will find a description of what was changed (and why)<BR>> in the following wiki pages:<BR>> <BR>> http://www.itk.org/Wiki/Proposals:Refactoring_Statistics_Framework_2007<BR>> <BR>> <BR>> <BR>> <BR>> Regards,<BR>> <BR>> <BR>> Luis<BR>> <BR>> <BR>> ------------------<BR>> Baoyun Li wrote:<BR>> > Dear All:<BR>> > I just figure out the problem. I need to use itk::GaussianMixtureModelComponent->Evaluate to make decision. The result is ok..<BR>> > 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.<BR>> > Can somebody tell me whether my code is wrong or I did not
used itk::GaussianDensityFunction->Evaluate() properly?<BR>> > Thanks<BR>> > Baoyun<BR>> ><BR>> > ------------------------------------------------------------------------<BR>> > *From:* Baoyun Li <<A href="mailto:baoyun_li123@yahoo.com" ymailto="mailto:baoyun_li123@yahoo.com">baoyun_li123@yahoo.com</A> <mailto:<A href="mailto:baoyun_li123@yahoo.com" ymailto="mailto:baoyun_li123@yahoo.com">baoyun_li123@yahoo.com</A>>><BR>> > *To:* Luis Ibanez <<A href="mailto:luis.ibanez@kitware.com" ymailto="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</A> <mailto:<A href="mailto:luis.ibanez@kitware.com" ymailto="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</A>>><BR>> > *Cc:* <A href="mailto:insight-users@itk.org" ymailto="mailto:insight-users@itk.org">insight-users@itk.org</A> <mailto:<A href="mailto:insight-users@itk.org"
ymailto="mailto:insight-users@itk.org">insight-users@itk.org</A>><BR>> > *Sent:* Tuesday, March 17, 2009 12:24:04 PM<BR>> > *Subject:* cannot get proper classification using itk:GaussianDensityFunction after EM clustering<BR>> ><BR>> > Dear ALL:<BR>> > 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.<BR>> > It produced mean value for Gray matter , whithe matter and CSF, the mean value looks ok to me.<BR>> > 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.<BR>> > Below is part of my code.<BR>> > 1, I first get the pararameter of
each component by : finalparameters=(components[i])->GetFullParameters();<BR>> > 2, Then I decompose the parameters to estimatedmean and estimatedcovariance<BR>> > 3, set the mean for GaussianDensityFunction by : membershipFunctions[i]->SetMean(&estimatedmean );<BR>> > membershipFunctions[i]->SetCovariance( &estimatedcovariance);<BR>> > 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<BR>> > 5, then I find the class with biggest pdf, assign the label .<BR>> > The code is listed below, can some body help me to find what is wrong.<BR>> > Thanks<BR>> > Baoyun<BR>> > ///////give
the mean value and covariance to GaussianDensityFunction typedef itk::Statistics::GaussianDensityFunction<ComponentType::MeasurementVectorType > MembershipFunctionType;<BR>> > std::vector< MembershipFunctionType::Pointer > membershipFunctions(numberOfClasses);<BR>> > unsigned int paramIndex;<BR>> > ParametersType finalparameters((NumberOfComponents+1)*NumberOfComponents);<BR>> > typedef MembershipFunctionType::MeanType MeanType;<BR>> > typedef MembershipFunctionType::CovarianceType CovarianceType;<BR>> > MeanType estimatedmean(NumberOfComponents);<BR>> > CovarianceType estimatedcovariance;<BR>> > typedef ComponentType::MeasurementVectorSizeType MeasurementVectorSizeType;<BR>> >
MeasurementVectorSizeType measurementVectorSize=NumberOfComponents;<BR>> > estimatedcovariance.SetSize( measurementVectorSize, measurementVectorSize );<BR>> > //estimatedmean.SetSize( measurementVectorSize, 1);<BR>> > // estimatedmean.Fill(0.0) ;<BR>> > for ( unsigned int i = 0 ; i < numberOfClasses ; i++ )<BR>> > {<BR>> > // membershipFunctions.push_back(MembershipFunctionType::New());<BR>> > membershipFunctions[i]=MembershipFunctionType::New();<BR>> > std::cout << " Size of Gaussian : ";<BR>> > std::cout << " " << (membershipFunctions[i])->GetMeasurementVectorSize() <<
std::endl;<BR>> > finalparameters=(components[i])->GetFullParameters();<BR>> > paramIndex=0; for (unsigned int i1 = 0 ; i1 < measurementVectorSize ; i1++)<BR>> > {<BR>> > estimatedmean[i1] = finalparameters[paramIndex] ;<BR>> > ++paramIndex ;<BR>> > }<BR>> > for (unsigned int i1 = 0 ; i1 < measurementVectorSize ; i1++ )<BR>> > {<BR>> > for (unsigned int j1 = 0 ; j1 < measurementVectorSize;
j1++ )<BR>> > {<BR>> > estimatedcovariance.GetVnlMatrix().put(i1, j1, finalparameters[paramIndex]) ;<BR>> > ++paramIndex ;<BR>> > }<BR>> > }<BR>> > // finalProportions[i]=(*estimator->GetProportions())[i];<BR>> > std::cout << "********************************" << std::endl;<BR>> > std::cout << "class[" << i << "]" << std::endl;<BR>> > std::cout << " Estimated Mean:" << std::endl;<BR>> > std::cout <<
" " << estimatedmean<BR>> > << std::endl;<BR>> > std::cout << " Estimated Covariance ";<BR>> > std::cout << " " << estimatedcovariance << std::endl;<BR>> > membershipFunctions[i]->SetMean(&estimatedmean );<BR>> > membershipFunctions[i]->SetCovariance( &estimatedcovariance);<BR>> > std::cout << "***************************" << std::endl;<BR>> > std::cout << "class[" << i << "]" << std::endl;<BR>> > std::cout << " Gaussain Mean:"
<< std::endl;<BR>> > std::cout << " " <<*(membershipFunctions[i]->GetMean()+0)<< std::endl;<BR>> > // std::cout << " " <<*(membershipFunctions[i]->GetMean()+1)<< std::endl;<BR>> > std::cout << " Gaussian Covariance ";<BR>> > std::cout << " " << *(membershipFunctions[i]->GetCovariance()+0) << std::endl;<BR>> > // std::cout << " " << *(membershipFunctions[i]->GetCovariance()+1) << std::endl;<BR>> > // std::cout << " " << *(membershipFunctions[i]->GetCovariance()+3) << std::endl;<BR>>
> }<BR>> > /////to lable the image typedef unsigned char OutputPixelType;<BR>> > typedef itk::Image< OutputPixelType, 3 > OutputImageType;<BR>> > OutputImageType::Pointer outputPtr=reader1->GetOutput();<BR>> > typedef itk::ImageRegionIterator< OutputImageType > ImageIterator;<BR>> > typedef VectorImageType::RegionType RegionType;<BR>> > RegionType region = outputPtr->GetBufferedRegion();<BR>> > //<BR>> > // ImageIterator pixel( outputPtr, region );<BR>> > typedef itk::Vector< double, numberOfClasses > EvaluationVectorType;<BR>> > EvaluationVectorType
eveluateresult;<BR>> > //pixel.GoToBegin();<BR>> > // itk::Array< double > finalProportions(numberOfClasses);<BR>> > for(unsigned char i=0;i<numberOfClasses;i++)<BR>> > {<BR>> > finalProportions[i]=(*estimator->GetProportions())[i];<BR>> > }<BR>> > double maxvalue;<BR>> > OutputPixelType classlabel;<BR>> > for ( pixel.GoToBegin(),constIterator.GoToBegin(); !pixel.IsAtEnd(); ++pixel,++constIterator )<BR>> > {<BR>> > mv=constIterator.Get();<BR>> >
accumulate1=0;<BR>> > maxvalue=0;<BR>> > for( unsigned int i=0;i<NumberOfComponents;i++)<BR>> > {<BR>> > accumulate1=accumulate1+mv[i];<BR>> > }<BR>> > if(accumulate1>20)<BR>> > {<BR>> > for(unsigned char i=0;i<numberOfClasses;i++)<BR>> > {<BR>> > eveluateresult[i]=(membershipFunctions[i]->Evaluate(mv))*finalProportions[i];<BR>> >
}<BR>> > for(unsigned char i=0;i<numberOfClasses;i++)<BR>> > {<BR>> > if(eveluateresult[i]>=maxvalue)<BR>> > {<BR>> > maxvalue=eveluateresult[i];<BR>> > classlabel=i+1;<BR>> > }<BR>> > // if(mv[0]==94&&mv[1]==77)<BR>> > // {<BR>> > //
std::cout << "evaluation result" << eveluateresult << "]" << std::endl;<BR>> > // }<BR>> > }<BR>> > pixel.Set(classlabel);<BR>> > }<BR>> > else<BR>> > {<BR>> > pixel.Set(0);<BR>> > }<BR>> > }<BR>> ><BR>> ><BR>> <BR></DIV></DIV></div><br>
</body></html>