[Insight-users] Error ->>> ImageToVectorImageFilter + ImageToListAdaptor

Ricardo Ferrari rjf.araraquara at gmail.com
Wed Dec 30 09:13:12 EST 2009


Hi Luis & Itk-users

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.

I really appreciate if you could help in solving this issue.

Thank you very much,
Ricardo

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.

Results from running the code:

ferrari at ferrari-desktop:~/Desktop/test$ bin/test HeadMRVolume.mhd
-----------------------------------------------------------------------
Mean vector estimated by using the KdTree-KMeans filter
[130.516, 59.1887, 5.77594]
-----------------------------------------------------------------------
-----------------------------------------------------------------------
Mean vector estimated by using the CovarianceSampleFilter filter
[4]
-----------------------------------------------------------------------

-----------------------------------------------------------------------
Covariance matrix estimated by using the CovarianceSampleFilter filter
17396

-----------------------------------------------------------------------
-----------------------------------------------------------------------
Mean vector estimated by using the CovarianceSampleFilter filter
[0]
-----------------------------------------------------------------------

-----------------------------------------------------------------------
Covariance matrix estimated by using the CovarianceSampleFilter filter
3755.77

-----------------------------------------------------------------------
-----------------------------------------------------------------------
Mean vector estimated by using the CovarianceSampleFilter filter
[-17606]
-----------------------------------------------------------------------

-----------------------------------------------------------------------
Covariance matrix estimated by using the CovarianceSampleFilter filter
3.10178e+08

-----------------------------------------------------------------------
ferrari at ferrari-desktop:~/Desktop/test$



















On Sun, Nov 8, 2009 at 10:15 PM, Luis Ibanez <luis.ibanez at kitware.com>wrote:

> Hi Ricardo,
>
> You should probably use the refactored Statistics framework.
>
> In this framework, improvements were made on the methods
> for adapting vector images to list samples.
>
> You will find the new code in the directory:
>
>           Insight/Code/Review/Statistics
>
> and you can enable it by reconfiguring your ITK build with CMake
> and turning ON the following two CMake variables:
>
>            * ITK_USE_REVIEW
>            * ITK_USE_REVIEW_STATISTICS
>
> For examples on the mechanism for adapting an image to a list
> you may want to  look at the code in the directory:
>
>
>  Insight/Testing/Code/Review/Statistics/
>                   itkImageToListSampleAdaptorTest2.cxx
>                   itkImageToListSampleAdaptorTest.cxx
>
>
> One of the improvements made in this code is that the management
> of multiple-components images was made more uniform with the
> management of scalar images.
>
>
>      Please give it a try and let us know if you find any problems,
>
>
>             Thanks
>
>
>                   Luis
>
>
>
> ----------------------------------------------------------------------------------------------
> On Sat, Nov 7, 2009 at 6:08 PM, Ricardo Ferrari
> <rjf.araraquara at gmail.com> wrote:
> > Hi Itk-users,
> >
> > After my message to Luis (please see below) I've found a way to create
> > vector samples from different image contrasts by using the
> itk::FixedArray
> > class.
> >
> > However, in addition to my previous question (which still remains) about
> how
> > to use the " ImageToVectorImageFilter + ImageToListAdaptor " to to build
> > vector samples (as performed with the itk::FixedArray), I do have another
> > question.
> >
> > Is there any way to define the number of contrasts (as used in the line
> > typedef itk::FixedArray< TInputPixelType, NumberOfContrasts >
> > TMeasurementVectorType; ) in the running time ?
> >
> > Thank you again,
> >
> > Ricardo
> >
> >
> >
> > ///
> > const int NumberOfContrasts = 1; //3;
> > const int Dimension = 3;
> >
> > /// Pixel type definition
> > typedef signed short
> > TInputPixelType;
> > typedef signed short
> > TOutputPixelType;
> >
> > /// Define type of the input and output images
> > typedef itk::Image< TInputPixelType, Dimension >
> > TInputImageType;
> > typedef itk::Image< TOutputPixelType, Dimension >
> > TOutputImageType;
> >
> >
> >     typedef itk::FixedArray< TInputPixelType, NumberOfContrasts >
> > TMeasurementVectorType;
> >     typedef itk::Image< TMeasurementVectorType, Dimension >
> TArrayImageType;
> >
> >     typedef itk::ScalarToArrayCastImageFilter< TInputImageType,
> > TArrayImageType > CasterType;
> >     CasterType::Pointer caster = CasterType::New();
> >     caster->SetInput( 0, img );
> >     caster->Update();
> >
> >     typedef itk::Statistics::ImageToListAdaptor<
> CasterType::OutputImageType
> >> ImageToListAdaptorType;
> >     ImageToListAdaptorType::Pointer adaptor =
> ImageToListAdaptorType::New();
> >     adaptor->SetImage( caster->GetOutput() );
> >
> >     ///
> >     /// Create the GMM
> >     ///
> >     TGMM< TArrayImageType, TOutputImageType > gmm;
> >     gmm.SetInputArrayImage( caster->GetOutput() );
> >
> >
> >
> >
> > -----
> > Hi Luis,
> >
> > I am trying to use the two following itk classes to get Vector Samples
> into
> > an Gaussian Mixture Model classifier. Although, I am following your
> > suggestion (please see
> > http://www.cmake.org/pipermail/insight-users/2007-April/022003.html ) I
> am
> > still getting an error.
> >
> > I really appreciate if you could help on this.
> >
> > Thanks,
> > Ricardo
> >
> >
> >
> > #include "io.h"
> > #include "itkImageToVectorImageFilter.
> > h"
> > #include "itkScalarToArrayCastImageFilter.h"
> > #include "itkImageToListAdaptor.h"
> >
> > /// Pixel type definition
> > typedef signed short
> >                  TInputPixelType;
> >
> > /// Define type of the input and output images
> > typedef itk::Image< TInputPixelType, Dimension >
> > TInputImageType;
> >
> >
> > ///
> > /// Main function
> > ///
> > int main( int argc, char **argv )
> > {
> >    // Read a minc image
> >    TInputImageType::Pointer img = ReadMincImage< TInputImageType >(
> > "test.mnc" );
> >
> >    typedef itk::ImageToVectorImageFilter< TInputImageType >
> > ImageToVectorImageFilterType;
> >    ImageToVectorImageFilterType::Pointer vectorImage =
> > ImageToVectorImageFilterType::New();
> >    vectorImage->SetNthInput( 0, img );
> >    vectorImage->Update();
> >
> >    typedef itk::Statistics::ImageToListAdaptor<
> > ImageToVectorImageFilterType::OutputImageType > ImageToListAdaptorType;
> >    ImageToListAdaptorType::Pointer adaptor =
> ImageToListAdaptorType::New();
> >    adaptor->SetImage( vectorImage->GetOutput() );
> >
> >    return 0;
> > }
> >
> >
> > [100%] Building CXX object
> > segmentation/gmm/CMakeFiles/gmm_classifier.dir/main.cpp.o
> > In file included from
> > /usr/local/include/InsightToolkit/Common/itkConceptChecking.h:23,
> >                 from
> > /usr/local/include/InsightToolkit/Common/itkImageHelper.h:20,
> >                 from
> > /usr/local/include/InsightToolkit/Common/itkImageBase.h:35,
> >                 from
> > /usr/local/include/InsightToolkit/Common/itkImage.h:20,
> >                 from
> /home/ferrari/Workspace/MIP_PROJECTS/trunk/io/io.h:6,
> >                 from
> > /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:2:
> > /usr/local/include/InsightToolkit/Common/itkPixelTraits.h: In
> instantiation
> > of ?itk::PixelTraits<itk::VariableLengthVector<short int> >?:
> >
> /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:97:
> > instantiated from
> > ?itk::Statistics::ImageToListAdaptor<itk::VectorImage<short int, 3u>,
> > itk::VariableLengthVector<short int> >?
> > /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:51:
> > instantiated from here
> > /usr/local/include/InsightToolkit/Common/itkPixelTraits.h:41: error:
> > ?Length? is not a member of ?itk::VariableLengthVector<short int>?
> > In file included from
> > /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:8:
> >
> /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:
> > In member function ?const TMeasurementVector&
> > itk::Statistics::ImageToListAdaptor<TImage,
> > TMeasurementVector>::GetMeasurementVector(const typename
> > TImage::PixelContainer::ElementIdentifier&) const [with TImage =
> > itk::VectorImage<short int, 3u>, TMeasurementVector =
> > itk::VariableLengthVector<short int>]?:
> > /home/ferrari/Workspace/MIP_PROJECTS/trunk/segmentation/gmm/main.cpp:56:
> > instantiated from here
> >
> /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:323:
> > warning: taking address of temporary
> >
> /usr/local/include/InsightToolkit/Numerics/Statistics/itkImageToListAdaptor.h:323:
> > warning: returning reference to temporary
> > make[2]: *** [segmentation/gmm/CMakeFiles/gmm_classifier.dir/main.cpp.o]
> > Error 1
> > make[1]: *** [segmentation/gmm/CMakeFiles/gmm_classifier.dir/all] Error 2
> > make: *** [all] Error 2
> > _____________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Kitware offers ITK Training Courses, for more information visit:
> > http://www.kitware.com/products/protraining.html
> >
> > Please keep messages on-topic and check the ITK FAQ at:
> > http://www.itk.org/Wiki/ITK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.itk.org/mailman/listinfo/insight-users
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091230/2b1a947e/attachment-0001.htm>
-------------- next part --------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.7)

SET( ProgramName "test" )

PROJECT( ${ProgramName} )

FIND_PACKAGE (ITK REQUIRED)
IF (ITK_FOUND)
	INCLUDE( ${USE_ITK_FILE} )
	SET(ITK_LIBRARIES ITKCommon ITKBasicFilters ITKIO ITKMetaIO ITKNumerics ITKStatistics itkvnl)
ENDIF(ITK_FOUND)

FIND_PACKAGE (VTK REQUIRED)
IF (VTK_FOUND)
	INCLUDE( ${USE_VTK_FILE} )
	SET(VTK_LIBRARIES vtkRendering vtkGraphics vtkWidgets vtkHybrid vtkImaging vtkIO vtkFiltering vtkCommon)
ENDIF( VTK_FOUND)

INCLUDE_DIRECTORIES(
	${CMAKE_CURRENT_SOURCE_DIR} 
)

SET( SRCS
)

ADD_EXECUTABLE( ${ProgramName}
    main.cpp
    ${SRCS} 
)

TARGET_LINK_LIBRARIES( ${ProgramName}
   	${VTK_LIBRARIES}
   	${ITK_LIBRARIES}
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 8148 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091230/2b1a947e/attachment-0001.cpp>


More information about the Insight-users mailing list