[Insight-users] PCAnalisys

Lydia Ng lng at insightful.com
Thu, 8 Jan 2004 05:01:57 -0800


Hi Lucas,

Have you tried to write out each of applyPCAShapeEstimator->GetInput(i) =
?
This might help to isolate if it is an IO problem or a filter problem?

- Lydia


> -----Original Message-----
> From: lucas [mailto:lucas at xserve.cvrti.utah.edu]
> Sent: Thursday, January 08, 2004 12:04 AM
> To: Luis Ibanez
> Cc: Insight-users at itk.org
> Subject: [Insight-users] PCAnalisys
>=20
> Hi Luis,
>=20
> I'm trying to perform a PCA on a set of training signed
> distance functions but although they are different from
> each other all the eigenvalues are zero.
> I think I might be making a mistake when loading the
> training datasets but I'm not sure.
> The following one is the code I'm using:
>=20
>=20
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "vnl/vnl_matrix_fixed.h"
> #include "vnl/vnl_math.h"
> #include "itkTextOutput.h"
> #include "itkVector.h"
> #include "itkImagePCAShapeModelEstimator.h"
>=20
>=20
> int main( int argc, char * argv[] )
> {
>    if( argc < 4 )
>      {
>      std::cerr << "Usage: " << argv[0];
>      std::cerr << std::endl;
>      return 1;
>      }
>=20
>    typedef short InputPixelType;
>    typedef double   OutputPixelType;
>=20
>    typedef itk::Image<InputPixelType,2> InputImageType;
>    typedef itk::Image<OutputPixelType,2> OutputImageType;
>=20
>    typedef itk::ImageFileReader< InputImageType  >
>  ReaderType;
>    typedef itk::ImageFileWriter< OutputImageType >
>  WriterType;
>=20
>    ReaderType::Pointer reader =3D ReaderType::New();
>    WriterType::Pointer writer =3D WriterType::New();
>=20
>    =
//---------------------------------------------------------------------
> -
>    =
//---------------------------------------------------------------------
> -
>    //Set the image model estimator
>    =
//---------------------------------------------------------------------
> -
>    typedef
> itk::ImagePCAShapeModelEstimator<InputImageType,
> OutputImageType>
>      ImagePCAShapeModelEstimatorType;
>=20
>    ImagePCAShapeModelEstimatorType::Pointer
>      applyPCAShapeEstimator =3D
> ImagePCAShapeModelEstimatorType::New();
>=20
>    =
//---------------------------------------------------------------------
> -
>    //Set the parameters of the clusterer
>    =
//---------------------------------------------------------------------
> -
>    applyPCAShapeEstimator->SetNumberOfTrainingImages(4);
>    applyPCAShapeEstimator->SetNumberOfPrincipalComponentsRequired(2);
>=20
>    reader->SetFileName( argv[1] );
>    reader->Update();
>    applyPCAShapeEstimator->SetInput(0,reader->GetOutput()
> );
>=20
>    reader->SetFileName( argv[2] );
>    reader->Update();
>    applyPCAShapeEstimator->SetInput(1,reader->GetOutput());
>=20
>    reader->SetFileName( argv[3] );
>    reader->Update();
>    applyPCAShapeEstimator->SetInput(2,
> reader->GetOutput());
>=20
>    reader->SetFileName( argv[4] );
>    reader->Update();
>    applyPCAShapeEstimator->SetInput(3,
> reader->GetOutput());
>=20
>    applyPCAShapeEstimator->Update();
>=20
>    =
//---------------------------------------------------------------------
> -
>    // Write the mean image
>    =
//---------------------------------------------------------------------
> -
>    writer->SetFileName("mean.vtk");
>    writer->SetInput(applyPCAShapeEstimator->GetOutput( 0 )
> );
>    try
>      {
>        writer->Update();
>      }
>    catch( itk::ExceptionObject exp )
>      {
>      std::cerr << "Exception caught ! mean writer" <<
> std::endl;
>      std::cerr <<     exp    << std::endl;
>      }
>=20
>     =
//--------------------------------------------------------------------
> --
>    // Write first mode image
>    =
//---------------------------------------------------------------------
> -
>    writer->SetFileName("1mode.vtk");
>    writer->SetInput(applyPCAShapeEstimator->GetOutput( 1 )
> );
>    try
>      {
>        writer->Update();
>      }
>    catch( itk::ExceptionObject exp )
>      {
>      std::cerr << "Exception caught ! 1st mode writer" <<
> std::endl;
>      std::cerr <<     exp    << std::endl;
>      }
>=20
>     =
//--------------------------------------------------------------------
> --
>    // Write second mode image
>    =
//---------------------------------------------------------------------
> -
>    writer->SetFileName("2mode.vtk");
>    writer->SetInput(applyPCAShapeEstimator->GetOutput( 2 )
> );
>    try
>      {
>        writer->Update();
>      }
>    catch( itk::ExceptionObject exp )
>      {
>      std::cerr << "Exception caught ! 2nd mode writer" <<
> std::endl;
>      std::cerr <<     exp    << std::endl;
>      }
>=20
>    vnl_vector<double> eigenValues =3D
>      applyPCAShapeEstimator->GetEigenValues();
>=20
>    for(unsigned int i=3D 0; i< 4 ; i++ )
>      {
>      std::cout << eigenValues[ i ] << std::endl;
>      }
>=20
>    return 0;
> }
>=20
> If you have any clue of what am I doing wrong please let
> me know.
> Thanks,
>=20
> Lucas Lorenzo
>=20
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users