Hi all,<div><br></div><div>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:</div><div><br></div><div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="'courier new', monospace" size="1"><span class="Apple-tab-span" style="white-space:pre">        </span>for ( unsigned int i = 0; i<NumberOfClasses; i++) {<br><span class="Apple-tab-span" style="white-space:pre">                </span>if (i==0) continue; // Background mean computation not yet implemented<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>// Weights array generation for this class<br><span class="Apple-tab-span" style="white-space:pre">                </span>typename ProbabilitySampleFilter::Pointer sampleFilter = ProbabilitySampleFilter::New();<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>sampleFilter->SetInput( m_Priors[i-1] );<br><span class="Apple-tab-span" style="white-space:pre">                </span>sampleFilter->SetMaskImage( m_MaskImage );<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>sampleFilter->Update();<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>ProbabilitySampleConstPointer sample = sampleFilter->GetOutput();<br><span class="Apple-tab-span" style="white-space:pre">                </span>if ( sample->Size() != m_Sample->Size() )<br>
<span class="Apple-tab-span" style="white-space:pre">                        </span>itkExceptionMacro("Sample sizes of components and prior for class " << i-1 << " do not match");<br><span class="Apple-tab-span" style="white-space:pre">                </span>typename MeanEstimatorType::WeightArrayType weights( sample->Size() );<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>weights.Fill(1.0);<br>/*<br><span class="Apple-tab-span" style="white-space:pre">                </span>typename ProbabilitySampleType::ConstIterator it = sample->Begin();<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>typename ProbabilitySampleType::ConstIterator end = sample->End();<br><br><span class="Apple-tab-span" style="white-space:pre">                </span>while( it!=end ) {<br>
<span class="Apple-tab-span" style="white-space:pre">                        </span>weights[it.GetInstanceIdentifier()] = it.GetMeasurementVector()[0];<br><span class="Apple-tab-span" style="white-space:pre">                        </span>++it;<br><span class="Apple-tab-span" style="white-space:pre">                </span>}<br>
*/<br><span class="Apple-tab-span" style="white-space:pre">                </span>// Weighted Mean estimation<br><span class="Apple-tab-span" style="white-space:pre">                </span>typename MeanEstimatorType::Pointer meanEst = MeanEstimatorType::New();<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>meanEst->SetInput(m_Sample);<br><span class="Apple-tab-span" style="white-space:pre">                </span>meanEst->SetWeights( weights );<br><span class="Apple-tab-span" style="white-space:pre">                </span>const typename MeanEstimatorType::MeasurementVectorDecoratedType * mean_out = meanEst->GetOutput();<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>try {<br><span class="Apple-tab-span" style="white-space:pre">                        </span>meanEst->Update();<br><span class="Apple-tab-span" style="white-space:pre">                </span>} catch( itk::ExceptionObject & ex ) {<br>
<span class="Apple-tab-span" style="white-space:pre">                        </span>std::cerr << "Exception caught" << ex << std::endl;<br><span class="Apple-tab-span" style="white-space:pre">                </span>}<br><span class="Apple-tab-span" style="white-space:pre">                </span>typename MeanEstimatorType::MeasurementVectorType mean = mean_out->Get();<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>std::cout << "Estimated mean for class " << i-1 << "= ";<br><span class="Apple-tab-span" style="white-space:pre">                <br></span><span class="Apple-tab-span" style="white-space:pre">                </span>for (unsigned int k; k< mean.GetSize(); k++) std::cout << mean[k] << ",";<br>
<span class="Apple-tab-span" style="white-space:pre">                <br></span><span class="Apple-tab-span" style="white-space:pre">                </span>std::cout<<std::endl;<br> }</font></blockquote></div><div><br></div><div>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.</div>
<div><br></div><div>Putting a breakpoint inside itkWeightedMeanSampleFilter::GenerateData() does not stop the debugger, and it reaches end without apparently generate output.</div><div><br></div><div>How could I resolve this problem?</div>
<div><br></div><div>Thank you very much in advance. Best regards,</div><div>Oscar Esteban</div><div><br>______________________________________<div><div><b>Oscar Esteban</b></div><div>PhD Student / Researcher</div><div><span style="color:rgb(153, 153, 153)"><br>
</span></div><div><span style="color:rgb(153, 153, 153)"><span style="color:rgb(192, 192, 192)">Biomedical Image Technologies (BIT), UPM<br>ETSI Telecomunicación Lab. C203, Av. Complutense s/n - E-28040 Madrid (Spain)<br>
+34 915 495 700 ext.4234</span></span></div><div><span style="color:rgb(153, 153, 153)"><br></span></div><font color="#c0c0c0">Signal Processing Laboratory (LTS5), EPFL-STI-IEL-LTS5<br>ELD 224 (Bâtiment ELD), Station 11, CH-1015 Lausanne, Switzerland<br>
</font></div><div></div><div></div><br>
</div>