[Insight-users] itkWeightedMeanSampleFilter is not calling GenerateData()
Oscar Esteban
oesteban at die.upm.es
Mon Oct 3 09:08:45 EDT 2011
Hi all,
I'm trying to compute a weighted mean for each class based on samples
obtained from corresponding priors. This is the code I am using:
for ( unsigned int i = 0; i<NumberOfClasses; i++) {
> if (i==0) continue; // Background mean computation not yet implemented
> // Weights array generation for this class
> typename ProbabilitySampleFilter::Pointer sampleFilter =
> ProbabilitySampleFilter::New();
> sampleFilter->SetInput( m_Priors[i-1] );
> sampleFilter->SetMaskImage( m_MaskImage );
> sampleFilter->Update();
> ProbabilitySampleConstPointer sample = sampleFilter->GetOutput();
> if ( sample->Size() != m_Sample->Size() )
> itkExceptionMacro("Sample sizes of components and prior for class " <<
> i-1 << " do not match");
> typename MeanEstimatorType::WeightArrayType weights( sample->Size() );
> weights.Fill(1.0);
> /*
> typename ProbabilitySampleType::ConstIterator it = sample->Begin();
> typename ProbabilitySampleType::ConstIterator end = sample->End();
>
> while( it!=end ) {
> weights[it.GetInstanceIdentifier()] = it.GetMeasurementVector()[0];
> ++it;
> }
> */
> // Weighted Mean estimation
> typename MeanEstimatorType::Pointer meanEst = MeanEstimatorType::New();
> meanEst->SetInput(m_Sample);
> meanEst->SetWeights( weights );
> const typename MeanEstimatorType::MeasurementVectorDecoratedType * mean_out
> = meanEst->GetOutput();
> try {
> meanEst->Update();
> } catch( itk::ExceptionObject & ex ) {
> std::cerr << "Exception caught" << ex << std::endl;
> }
> typename MeanEstimatorType::MeasurementVectorType mean = mean_out->Get();
> std::cout << "Estimated mean for class " << i-1 << "= ";
>
> for (unsigned int k; k< mean.GetSize(); k++) std::cout << mean[k] << ",";
>
> std::cout<<std::endl;
> }
When debugging, I found that meanEst->Update() seems to be doing nothing.
Watching at the variable, mean has m_NumElements=0. Although, sample seems
to be OK. No exception is thrown, but I can't get the means value. I also
checked with weights.Fill(1.0) that the problem is not those weights.
Putting a breakpoint inside itkWeightedMeanSampleFilter::GenerateData() does
not stop the debugger, and it reaches end without apparently generate
output.
How could I resolve this problem?
Thank you very much in advance. Best regards,
Oscar Esteban
______________________________________
*Oscar Esteban*
PhD Student / Researcher
Biomedical Image Technologies (BIT), UPM
ETSI Telecomunicación Lab. C203, Av. Complutense s/n - E-28040 Madrid
(Spain)
+34 915 495 700 ext.4234
Signal Processing Laboratory (LTS5), EPFL-STI-IEL-LTS5
ELD 224 (Bâtiment ELD), Station 11, CH-1015 Lausanne, Switzerland
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20111003/0b09b293/attachment.htm>
More information about the Insight-users
mailing list