Hi Luis & 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 & 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"><<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>></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>
<<a href="mailto:rjf.araraquara@gmail.com">rjf.araraquara@gmail.com</a>> wrote:<br>
</div><div><div></div><div class="h5">> Hi Itk-users,<br>
><br>
> After my message to Luis (please see below) I've found a way to create<br>
> vector samples from different image contrasts by using the itk::FixedArray<br>
> class.<br>
><br>
> However, in addition to my previous question (which still remains) about how<br>
> to use the " ImageToVectorImageFilter + ImageToListAdaptor " to to build<br>
> vector samples (as performed with the itk::FixedArray), I do have another<br>
> question.<br>
><br>
> Is there any way to define the number of contrasts (as used in the line<br>
> typedef itk::FixedArray< TInputPixelType, NumberOfContrasts ><br>
> TMeasurementVectorType; ) in the running time ?<br>
><br>
> Thank you again,<br>
><br>
> Ricardo<br>
><br>
><br>
><br>
> ///<br>
> const int NumberOfContrasts = 1; //3;<br>
> const int Dimension = 3;<br>
><br>
> /// Pixel type definition<br>
> typedef signed short<br>
> TInputPixelType;<br>
> typedef signed short<br>
> TOutputPixelType;<br>
><br>
> /// Define type of the input and output images<br>
> typedef itk::Image< TInputPixelType, Dimension ><br>
> TInputImageType;<br>
> typedef itk::Image< TOutputPixelType, Dimension ><br>
> TOutputImageType;<br>
><br>
><br>
> typedef itk::FixedArray< TInputPixelType, NumberOfContrasts ><br>
> TMeasurementVectorType;<br>
> typedef itk::Image< TMeasurementVectorType, Dimension > TArrayImageType;<br>
><br>
> typedef itk::ScalarToArrayCastImageFilter< TInputImageType,<br>
> TArrayImageType > CasterType;<br>
> CasterType::Pointer caster = CasterType::New();<br>
> caster->SetInput( 0, img );<br>
> caster->Update();<br>
><br>
> typedef itk::Statistics::ImageToListAdaptor< CasterType::OutputImageType<br>
>> ImageToListAdaptorType;<br>
> ImageToListAdaptorType::Pointer adaptor = ImageToListAdaptorType::New();<br>
> adaptor->SetImage( caster->GetOutput() );<br>
><br>
> ///<br>
> /// Create the GMM<br>
> ///<br>
> TGMM< TArrayImageType, TOutputImageType > gmm;<br>
> gmm.SetInputArrayImage( caster->GetOutput() );<br>
><br>
><br>
><br>
><br>
> -----<br>
> Hi Luis,<br>
><br>
> I am trying to use the two following itk classes to get Vector Samples into<br>
> an Gaussian Mixture Model classifier. Although, I am following your<br>
> suggestion (please see<br>
> <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>
> still getting an error.<br>
><br>
> I really appreciate if you could help on this.<br>
><br>
> Thanks,<br>
> Ricardo<br>
><br>
><br>
><br>
> #include "io.h"<br>
> #include "itkImageToVectorImageFilter.<br>
> h"<br>
> #include "itkScalarToArrayCastImageFilter.h"<br>
> #include "itkImageToListAdaptor.h"<br>
><br>
> /// Pixel type definition<br>
> typedef signed short<br>
> TInputPixelType;<br>
><br>
> /// Define type of the input and output images<br>
> typedef itk::Image< TInputPixelType, Dimension ><br>
> TInputImageType;<br>
><br>
><br>
> ///<br>
> /// Main function<br>
> ///<br>
> int main( int argc, char **argv )<br>
> {<br>
> // Read a minc image<br>
> TInputImageType::Pointer img = ReadMincImage< TInputImageType >(<br>
> "test.mnc" );<br>
><br>
> typedef itk::ImageToVectorImageFilter< TInputImageType ><br>
> ImageToVectorImageFilterType;<br>
> ImageToVectorImageFilterType::Pointer vectorImage =<br>
> ImageToVectorImageFilterType::New();<br>
> vectorImage->SetNthInput( 0, img );<br>
> vectorImage->Update();<br>
><br>
> typedef itk::Statistics::ImageToListAdaptor<<br>
> ImageToVectorImageFilterType::OutputImageType > ImageToListAdaptorType;<br>
> ImageToListAdaptorType::Pointer adaptor = ImageToListAdaptorType::New();<br>
> adaptor->SetImage( vectorImage->GetOutput() );<br>
><br>
> return 0;<br>
> }<br>
><br>
><br>
> [100%] Building CXX object<br>
> segmentation/gmm/CMakeFiles/gmm_classifier.dir/main.cpp.o<br>
> In file included from<br>
> /usr/local/include/InsightToolkit/Common/itkConceptChecking.h:23,<br>
> from<br>
> /usr/local/include/InsightToolkit/Common/itkImageHelper.h:20,<br>
> from<br>
> /usr/local/include/InsightToolkit/Common/itkImageBase.h:35,<br>
> from<br>
> /usr/local/include/InsightToolkit/Common/itkImage.h:20,<br>
> from /home/ferrari/Workspace/MIP_PROJECTS/trunk/io/io.h:6,<br>
> from<br>
> /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:2:<br>
> /usr/local/include/InsightToolkit/Common/itkPixelTraits.h: In instantiation<br>
> of ?itk::PixelTraits<itk::VariableLengthVector<short int> >?:<br>
> /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:97:<br>
> instantiated from<br>
> ?itk::Statistics::ImageToListAdaptor<itk::VectorImage<short int, 3u>,<br>
> itk::VariableLengthVector<short int> >?<br>
> /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:51:<br>
> instantiated from here<br>
> /usr/local/include/InsightToolkit/Common/itkPixelTraits.h:41: error:<br>
> ?Length? is not a member of ?itk::VariableLengthVector<short int>?<br>
> In file included from<br>
> /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:8:<br>
> /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:<br>
> In member function ?const TMeasurementVector&<br>
> itk::Statistics::ImageToListAdaptor<TImage,<br>
> TMeasurementVector>::GetMeasurementVector(const typename<br>
> TImage::PixelContainer::ElementIdentifier&) const [with TImage =<br>
> itk::VectorImage<short int, 3u>, TMeasurementVector =<br>
> itk::VariableLengthVector<short int>]?:<br>
> /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:56:<br>
> instantiated from here<br>
> /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:323:<br>
> warning: taking address of temporary<br>
> /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:323:<br>
> warning: returning reference to temporary<br>
> make[2]: *** [segmentation/gmm/CMakeFiles/gmm_classifier.dir/main.cpp.o]<br>
> Error 1<br>
> make[1]: *** [segmentation/gmm/CMakeFiles/gmm_classifier.dir/all] Error 2<br>
> make: *** [all] Error 2<br>
</div></div><div><div></div><div class="h5">> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
><br>
><br>
</div></div></blockquote></div><br>