Hi all,<div><br></div><div>I&#39;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="&#39;courier new&#39;, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre">        </span>for ( unsigned int i = 0; i&lt;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-&gt;SetInput( m_Priors[i-1] );<br><span class="Apple-tab-span" style="white-space:pre">                </span>sampleFilter-&gt;SetMaskImage( m_MaskImage );<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>sampleFilter-&gt;Update();<br>
<span class="Apple-tab-span" style="white-space:pre">                </span>ProbabilitySampleConstPointer sample = sampleFilter-&gt;GetOutput();<br><span class="Apple-tab-span" style="white-space:pre">                </span>if ( sample-&gt;Size() != m_Sample-&gt;Size() )<br>

<span class="Apple-tab-span" style="white-space:pre">                        </span>itkExceptionMacro(&quot;Sample sizes of components and prior for class &quot; &lt;&lt; i-1 &lt;&lt; &quot; do not match&quot;);<br><span class="Apple-tab-span" style="white-space:pre">                </span>typename MeanEstimatorType::WeightArrayType weights( sample-&gt;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-&gt;Begin();<br>

<span class="Apple-tab-span" style="white-space:pre">                </span>typename ProbabilitySampleType::ConstIterator end = sample-&gt;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-&gt;SetInput(m_Sample);<br><span class="Apple-tab-span" style="white-space:pre">                </span>meanEst-&gt;SetWeights( weights );<br><span class="Apple-tab-span" style="white-space:pre">                </span>const typename MeanEstimatorType::MeasurementVectorDecoratedType * mean_out = meanEst-&gt;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-&gt;Update();<br><span class="Apple-tab-span" style="white-space:pre">                </span>} catch( itk::ExceptionObject &amp; ex ) {<br>

<span class="Apple-tab-span" style="white-space:pre">                        </span>std::cerr &lt;&lt; &quot;Exception caught&quot; &lt;&lt; ex &lt;&lt; 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-&gt;Get();<br>

<span class="Apple-tab-span" style="white-space:pre">                </span>std::cout &lt;&lt; &quot;Estimated mean for class &quot; &lt;&lt; i-1 &lt;&lt; &quot;= &quot;;<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&lt; mean.GetSize(); k++) std::cout &lt;&lt; mean[k] &lt;&lt; &quot;,&quot;;<br>

<span class="Apple-tab-span" style="white-space:pre">                <br></span><span class="Apple-tab-span" style="white-space:pre">                </span>std::cout&lt;&lt;std::endl;<br>          }</font></blockquote></div><div><br></div><div>When debugging, I found that meanEst-&gt;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&#39;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>