Hi Luis &amp; Itk-users<br><br>After Luis suggestion (please see bellow), I have changed my codes and now I am having problems in using the itk::Statistics::CovarianceSampleFilter.  I am sending you a minimal sample example (main.cpp and CMakeLists.txt) attached to this e-mail where I am trying to replicate the problem. I have already tried to find the problem but I am not quite familiar with the itk::Sample class.  In my opinion, it seems that the SubSample obtained from the SampleClassifierFilterType::MembershipSampleType* membershipSample are not being properly treated by the itk::Statistics::CovarianceSampleFilter. <br>
<br>I really appreciate if you could help in solving this issue.<br><br>Thank you very much,<br>Ricardo<br><br>PS: For testing the code I am sending you I have used the HeadMRVolume.mhd &amp; HeadMRVolume.raw files from the VTK/VTKData/Data. They are too large to attached to this e-mail.<br>
<br>Results from running the code:<br><br>ferrari@ferrari-desktop:~/Desktop/test$ bin/test HeadMRVolume.mhd <br>-----------------------------------------------------------------------<br>Mean vector estimated by using the KdTree-KMeans filter                <br>
[130.516, 59.1887, 5.77594]<br>-----------------------------------------------------------------------<br>-----------------------------------------------------------------------<br>Mean vector estimated by using the CovarianceSampleFilter filter       <br>
[4]<br>-----------------------------------------------------------------------<br><br>-----------------------------------------------------------------------<br>Covariance matrix estimated by using the CovarianceSampleFilter filter <br>
17396 <br><br>-----------------------------------------------------------------------<br>-----------------------------------------------------------------------<br>Mean vector estimated by using the CovarianceSampleFilter filter       <br>
[0]<br>-----------------------------------------------------------------------<br><br>-----------------------------------------------------------------------<br>Covariance matrix estimated by using the CovarianceSampleFilter filter <br>
3755.77 <br><br>-----------------------------------------------------------------------<br>-----------------------------------------------------------------------<br>Mean vector estimated by using the CovarianceSampleFilter filter       <br>
[-17606]<br>-----------------------------------------------------------------------<br><br>-----------------------------------------------------------------------<br>Covariance matrix estimated by using the CovarianceSampleFilter filter <br>
3.10178e+08 <br><br>-----------------------------------------------------------------------<br>ferrari@ferrari-desktop:~/Desktop/test$ <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><div class="gmail_quote">
On Sun, Nov 8, 2009 at 10:15 PM, Luis Ibanez <span dir="ltr">&lt;<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Hi Ricardo,<br>
<br>
You should probably use the refactored Statistics framework.<br>
<br>
In this framework, improvements were made on the methods<br>
for adapting vector images to list samples.<br>
<br>
You will find the new code in the directory:<br>
<br>
           Insight/Code/Review/Statistics<br>
<br>
and you can enable it by reconfiguring your ITK build with CMake<br>
and turning ON the following two CMake variables:<br>
<br>
            * ITK_USE_REVIEW<br>
            * ITK_USE_REVIEW_STATISTICS<br>
<br>
For examples on the mechanism for adapting an image to a list<br>
you may want to  look at the code in the directory:<br>
<br>
<br>
  Insight/Testing/Code/Review/Statistics/<br>
                   itkImageToListSampleAdaptorTest2.cxx<br>
                   itkImageToListSampleAdaptorTest.cxx<br>
<br>
<br>
One of the improvements made in this code is that the management<br>
of multiple-components images was made more uniform with the<br>
management of scalar images.<br>
<br>
<br>
      Please give it a try and let us know if you find any problems,<br>
<br>
<br>
             Thanks<br>
<br>
<br>
                   Luis<br>
<br>
<br>
----------------------------------------------------------------------------------------------<br>
On Sat, Nov 7, 2009 at 6:08 PM, Ricardo Ferrari<br>
&lt;<a href="mailto:rjf.araraquara@gmail.com">rjf.araraquara@gmail.com</a>&gt; wrote:<br>
</div><div><div></div><div class="h5">&gt; Hi Itk-users,<br>
&gt;<br>
&gt; After my message to Luis (please see below) I&#39;ve found a way to create<br>
&gt; vector samples from different image contrasts by using the itk::FixedArray<br>
&gt; class.<br>
&gt;<br>
&gt; However, in addition to my previous question (which still remains) about how<br>
&gt; to use the &quot; ImageToVectorImageFilter + ImageToListAdaptor &quot; to to build<br>
&gt; vector samples (as performed with the itk::FixedArray), I do have another<br>
&gt; question.<br>
&gt;<br>
&gt; Is there any way to define the number of contrasts (as used in the line<br>
&gt; typedef itk::FixedArray&lt; TInputPixelType, NumberOfContrasts &gt;<br>
&gt; TMeasurementVectorType; ) in the running time ?<br>
&gt;<br>
&gt; Thank you again,<br>
&gt;<br>
&gt; Ricardo<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; ///<br>
&gt; const int NumberOfContrasts = 1; //3;<br>
&gt; const int Dimension = 3;<br>
&gt;<br>
&gt; /// Pixel type definition<br>
&gt; typedef signed short<br>
&gt; TInputPixelType;<br>
&gt; typedef signed short<br>
&gt; TOutputPixelType;<br>
&gt;<br>
&gt; /// Define type of the input and output images<br>
&gt; typedef itk::Image&lt; TInputPixelType, Dimension &gt;<br>
&gt; TInputImageType;<br>
&gt; typedef itk::Image&lt; TOutputPixelType, Dimension &gt;<br>
&gt; TOutputImageType;<br>
&gt;<br>
&gt;<br>
&gt;     typedef itk::FixedArray&lt; TInputPixelType, NumberOfContrasts &gt;<br>
&gt; TMeasurementVectorType;<br>
&gt;     typedef itk::Image&lt; TMeasurementVectorType, Dimension &gt; TArrayImageType;<br>
&gt;<br>
&gt;     typedef itk::ScalarToArrayCastImageFilter&lt; TInputImageType,<br>
&gt; TArrayImageType &gt; CasterType;<br>
&gt;     CasterType::Pointer caster = CasterType::New();<br>
&gt;     caster-&gt;SetInput( 0, img );<br>
&gt;     caster-&gt;Update();<br>
&gt;<br>
&gt;     typedef itk::Statistics::ImageToListAdaptor&lt; CasterType::OutputImageType<br>
&gt;&gt; ImageToListAdaptorType;<br>
&gt;     ImageToListAdaptorType::Pointer adaptor = ImageToListAdaptorType::New();<br>
&gt;     adaptor-&gt;SetImage( caster-&gt;GetOutput() );<br>
&gt;<br>
&gt;     ///<br>
&gt;     /// Create the GMM<br>
&gt;     ///<br>
&gt;     TGMM&lt; TArrayImageType, TOutputImageType &gt; gmm;<br>
&gt;     gmm.SetInputArrayImage( caster-&gt;GetOutput() );<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; -----<br>
&gt; Hi Luis,<br>
&gt;<br>
&gt; I am trying to use the two following itk classes to get Vector Samples into<br>
&gt; an Gaussian Mixture Model classifier. Although, I am following your<br>
&gt; suggestion (please see<br>
&gt; <a href="http://www.cmake.org/pipermail/insight-users/2007-April/022003.html" target="_blank">http://www.cmake.org/pipermail/insight-users/2007-April/022003.html</a> ) I am<br>
&gt; still getting an error.<br>
&gt;<br>
&gt; I really appreciate if you could help on this.<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Ricardo<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; #include &quot;io.h&quot;<br>
&gt; #include &quot;itkImageToVectorImageFilter.<br>
&gt; h&quot;<br>
&gt; #include &quot;itkScalarToArrayCastImageFilter.h&quot;<br>
&gt; #include &quot;itkImageToListAdaptor.h&quot;<br>
&gt;<br>
&gt; /// Pixel type definition<br>
&gt; typedef signed short<br>
&gt;                  TInputPixelType;<br>
&gt;<br>
&gt; /// Define type of the input and output images<br>
&gt; typedef itk::Image&lt; TInputPixelType, Dimension &gt;<br>
&gt; TInputImageType;<br>
&gt;<br>
&gt;<br>
&gt; ///<br>
&gt; /// Main function<br>
&gt; ///<br>
&gt; int main( int argc, char **argv )<br>
&gt; {<br>
&gt;    // Read a minc image<br>
&gt;    TInputImageType::Pointer img = ReadMincImage&lt; TInputImageType &gt;(<br>
&gt; &quot;test.mnc&quot; );<br>
&gt;<br>
&gt;    typedef itk::ImageToVectorImageFilter&lt; TInputImageType &gt;<br>
&gt; ImageToVectorImageFilterType;<br>
&gt;    ImageToVectorImageFilterType::Pointer vectorImage =<br>
&gt; ImageToVectorImageFilterType::New();<br>
&gt;    vectorImage-&gt;SetNthInput( 0, img );<br>
&gt;    vectorImage-&gt;Update();<br>
&gt;<br>
&gt;    typedef itk::Statistics::ImageToListAdaptor&lt;<br>
&gt; ImageToVectorImageFilterType::OutputImageType &gt; ImageToListAdaptorType;<br>
&gt;    ImageToListAdaptorType::Pointer adaptor = ImageToListAdaptorType::New();<br>
&gt;    adaptor-&gt;SetImage( vectorImage-&gt;GetOutput() );<br>
&gt;<br>
&gt;    return 0;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt; [100%] Building CXX object<br>
&gt; segmentation/gmm/CMakeFiles/gmm_classifier.dir/main.cpp.o<br>
&gt; In file included from<br>
&gt; /usr/local/include/InsightToolkit/Common/itkConceptChecking.h:23,<br>
&gt;                 from<br>
&gt; /usr/local/include/InsightToolkit/Common/itkImageHelper.h:20,<br>
&gt;                 from<br>
&gt; /usr/local/include/InsightToolkit/Common/itkImageBase.h:35,<br>
&gt;                 from<br>
&gt; /usr/local/include/InsightToolkit/Common/itkImage.h:20,<br>
&gt;                 from /home/ferrari/Workspace/MIP_PROJECTS/trunk/io/io.h:6,<br>
&gt;                 from<br>
&gt; /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:2:<br>
&gt; /usr/local/include/InsightToolkit/Common/itkPixelTraits.h: In instantiation<br>
&gt; of ?itk::PixelTraits&lt;itk::VariableLengthVector&lt;short int&gt; &gt;?:<br>
&gt; /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:97:<br>
&gt; instantiated from<br>
&gt; ?itk::Statistics::ImageToListAdaptor&lt;itk::VectorImage&lt;short int, 3u&gt;,<br>
&gt; itk::VariableLengthVector&lt;short int&gt; &gt;?<br>
&gt; /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:51:<br>
&gt; instantiated from here<br>
&gt; /usr/local/include/InsightToolkit/Common/itkPixelTraits.h:41: error:<br>
&gt; ?Length? is not a member of ?itk::VariableLengthVector&lt;short int&gt;?<br>
&gt; In file included from<br>
&gt; /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:8:<br>
&gt; /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:<br>
&gt; In member function ?const TMeasurementVector&amp;<br>
&gt; itk::Statistics::ImageToListAdaptor&lt;TImage,<br>
&gt; TMeasurementVector&gt;::GetMeasurementVector(const typename<br>
&gt; TImage::PixelContainer::ElementIdentifier&amp;) const [with TImage =<br>
&gt; itk::VectorImage&lt;short int, 3u&gt;, TMeasurementVector =<br>
&gt; itk::VariableLengthVector&lt;short int&gt;]?:<br>
&gt; /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:56:<br>
&gt; instantiated from here<br>
&gt; /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:323:<br>
&gt; warning: taking address of temporary<br>
&gt; /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:323:<br>
&gt; warning: returning reference to temporary<br>
&gt; make[2]: *** [segmentation/gmm/CMakeFiles/gmm_classifier.dir/main.cpp.o]<br>
&gt; Error 1<br>
&gt; make[1]: *** [segmentation/gmm/CMakeFiles/gmm_classifier.dir/all] Error 2<br>
&gt; make: *** [all] Error 2<br>
</div></div><div><div></div><div class="h5">&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt; <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br>