Hi all,<div><br></div><div>I found out that <span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">itk::WeightedMeanSampleFilter< TSample > does not correctly initializes the MeasurementVector when using a ListSample with itk::VariableLengthVector.</span></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, sans-serif">I tried modifying Code/Review/Statistics/itkWeightedMeanSampleFilter.txx, line 98, adding a new line after, with output.SetSize( measurementVectorSize ). But I get a compilation error (SetSize is not a member of...)</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, sans-serif">How should I correct this issue? (Or, how should I use this filter when using VariableLengthVectors?)</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, sans-serif">Thanks. Regards,</font></div><div><font class="Apple-style-span" face="arial, sans-serif">Oscar Esteban</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><br></font></div><div><div><div><div><b>______________________________________</b></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>
<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Oscar Esteban</b> <span dir="ltr"><<a href="mailto:oesteban@die.upm.es">oesteban@die.upm.es</a>></span><br>
Date: 3 October 2011 15:08<br>Subject: itkWeightedMeanSampleFilter is not calling GenerateData()<br>To: <a href="mailto:insight-users@itk.org">insight-users@itk.org</a><br><br><br>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 face="'courier new', monospace" size="1"><span style="white-space:pre-wrap">        </span>for ( unsigned int i = 0; i<NumberOfClasses; i++) {<br><span style="white-space:pre-wrap">                </span>if (i==0) continue; // Background mean computation not yet implemented<br>
<span style="white-space:pre-wrap">                </span>// Weights array generation for this class<br><span style="white-space:pre-wrap">                </span>typename ProbabilitySampleFilter::Pointer sampleFilter = ProbabilitySampleFilter::New();<br>
<span style="white-space:pre-wrap">                </span>sampleFilter->SetInput( m_Priors[i-1] );<br><span style="white-space:pre-wrap">                </span>sampleFilter->SetMaskImage( m_MaskImage );<br><span style="white-space:pre-wrap">                </span>sampleFilter->Update();<br>
<span style="white-space:pre-wrap">                </span>ProbabilitySampleConstPointer sample = sampleFilter->GetOutput();<br><span style="white-space:pre-wrap">                </span>if ( sample->Size() != m_Sample->Size() )<br>
<span style="white-space:pre-wrap">                        </span>itkExceptionMacro("Sample sizes of components and prior for class " << i-1 << " do not match");<br><span style="white-space:pre-wrap">                </span>typename MeanEstimatorType::WeightArrayType weights( sample->Size() );<br>
<span style="white-space:pre-wrap">                </span>weights.Fill(1.0);<br>/*<br><span style="white-space:pre-wrap">                </span>typename ProbabilitySampleType::ConstIterator it = sample->Begin();<br>
<span style="white-space:pre-wrap">                </span>typename ProbabilitySampleType::ConstIterator end = sample->End();<br><br><span style="white-space:pre-wrap">                </span>while( it!=end ) {<br>
<span style="white-space:pre-wrap">                        </span>weights[it.GetInstanceIdentifier()] = it.GetMeasurementVector()[0];<br><span style="white-space:pre-wrap">                        </span>++it;<br><span style="white-space:pre-wrap">                </span>}<br>
*/<br><span style="white-space:pre-wrap">                </span>// Weighted Mean estimation<br><span style="white-space:pre-wrap">                </span>typename MeanEstimatorType::Pointer meanEst = MeanEstimatorType::New();<br>
<span style="white-space:pre-wrap">                </span>meanEst->SetInput(m_Sample);<br><span style="white-space:pre-wrap">                </span>meanEst->SetWeights( weights );<br><span style="white-space:pre-wrap">                </span>const typename MeanEstimatorType::MeasurementVectorDecoratedType * mean_out = meanEst->GetOutput();<br>
<span style="white-space:pre-wrap">                </span>try {<br><span style="white-space:pre-wrap">                        </span>meanEst->Update();<br><span style="white-space:pre-wrap">                </span>} catch( itk::ExceptionObject & ex ) {<br>
<span style="white-space:pre-wrap">                        </span>std::cerr << "Exception caught" << ex << std::endl;<br><span style="white-space:pre-wrap">                </span>}<br><span style="white-space:pre-wrap">                </span>typename MeanEstimatorType::MeasurementVectorType mean = mean_out->Get();<br>
<span style="white-space:pre-wrap">                </span>std::cout << "Estimated mean for class " << i-1 << "= ";<br><span style="white-space:pre-wrap">                <br></span><span style="white-space:pre-wrap">                </span>for (unsigned int k; k< mean.GetSize(); k++) std::cout << mean[k] << ",";<br>
<span style="white-space:pre-wrap">                <br></span><span style="white-space:pre-wrap">                </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>
<a href="tel:%2B34%20915%20495%20700%20ext.4234" value="+34915495700" target="_blank">+34 915 495 700 ext.4234</a></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>
</div><br></div></div>