[Insight-users] Re: Active Shape Models Segmentation
Ilaria Canova Calori
canovaca at stud.ntnu.no
Mon Jan 10 04:02:51 EST 2005
Hi Luis,
here I attach my modified version of the
itkImagePCAShapeModelEstimatorTest.cxx, which returns a mean image and
black principal component images.
----------------------------------------------------------------------
// Insight classes
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkLightProcessObject.h"
#include "itkImagePCAShapeModelEstimator.h"
int main(int argc, char *argv[] )
{
if( argc < 5 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " meanOutputFile firstPrincipalComponent
secondPrincipalComponent ";
std::cerr << " MaxNumShape firstShapeModel second ... " <<std::endl;
return 1;
}
typedef unsigned char PixelType;
const unsigned int Dimension = 2;
const unsigned int NUMTRAINIMAGES = 3;
const unsigned int NUMLARGESTPC = 2;
typedef itk::Image<PixelType,Dimension> InputImageType;
typedef itk::Image<PixelType,Dimension> OutputImageType;
typedef itk::Image<PixelType,Dimension> MeanImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer1 = WriterType::New();
WriterType::Pointer writer2 = WriterType::New();
typedef itk::ImagePCAShapeModelEstimator<InputImageType,
OutputImageType>
ImagePCAShapeModelEstimatorType;
ImagePCAShapeModelEstimatorType::Pointer
applyPCAShapeEstimator = ImagePCAShapeModelEstimatorType::New();
applyPCAShapeEstimator->SetNumberOfTrainingImages( NUMTRAINIMAGES );
applyPCAShapeEstimator->SetNumberOfPrincipalComponentsRequired(
NUMLARGESTPC );
const unsigned int max = atoi( argv[4] );
for(unsigned int i=0; i<max; i++)
{
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[5+i] );
reader->Update();
InputImageType::Pointer image = InputImageType::New();
InputImageType::SizeType inputImageSize ;
inputImageSize =
reader->GetOutput()->GetRequestedRegion().GetSize();
InputImageType::IndexType index;
index.Fill(0);
InputImageType::RegionType region;
region.SetSize( inputImageSize );
region.SetIndex( index );
image->SetLargestPossibleRegion( region );
image->SetBufferedRegion( region );
image->Allocate();
image = reader->GetOutput();
applyPCAShapeEstimator->SetInput(i, image);
}
applyPCAShapeEstimator->Update();
//Print the eigen vectors
vnl_vector<double> eigenValues =
applyPCAShapeEstimator->GetEigenValues();
unsigned int numEigVal = eigenValues.size();
std::cout << "Number of returned eign-values: " << numEigVal <<
std::endl;
std::cout << "The " <<
applyPCAShapeEstimator->GetNumberOfPrincipalComponentsRequired() <<
" largest eigen values are:" << std::endl;
for(unsigned int i= 0; i< vnl_math_min( numEigVal, (unsigned
int)NUMLARGESTPC ); i++ )
{
std::cout << eigenValues[ i ] << std::ends;
}
std::cout << "" << std::endl;
std::cout << "" << std::endl;
//Print the OutputImage
for ( unsigned int j=0; j<NUMLARGESTPC+1 ; j++)
{
OutputImageType::Pointer outImage =
applyPCAShapeEstimator->GetOutput( j );
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[1+j]);
writer->SetInput(outImage);
writer->Update();
}
//Test for the eigen values for the test case precomputed using
Matlab/Splus
std::cout << "" << std::endl;
if( (eigenValues[2] < 6 || eigenValues[2] > 6.1) || (eigenValues[1]
>0.1) )
std::cout<< "Test Passed" << std::endl;
else
std::cout<< "Test failed" << std::endl;
return 0;
}
-----------------------------------------------------------------------
I also attach some pictures: the lumen pictures are in succession, so
the lumens are centred, but the ASM pictures are not so the mean image
is not what I expected, so I would like to write a filter to find a
centre of gravity in the middle of the lumen to recentre the images. I
have already wrote the code to find the centre of gravity in Matlab,
now I will try with ITK.
Thanks,
Ilaria Canova Calori
Scrive Luis Ibanez <luis.ibanez at kitware.com>:
>
> Hi Ilaria,
>
> Can you please post to the list your modified version of
> the itkImagePCAShapeModelEstimatorTest.cxx ?
>
> In that way we can try to reproduce the problem that you
> are reporting.
>
>
> Thanks,
>
>
> Luis
>
>
> ---------------------------
> Ilaria Canova Calori wrote:
>
> > Hi,
> >
> > I have changed the code, using a different reader for each training
> > images. Now I get the mean image and the largest eigen value but I
> > donĀ“t get any principal components, just a black picture.
> >
> > Regards,
> > Ilaria Canova Calori
> >
> > Scrive Ilaria Canova Calori <canovaca at stud.ntnu.no>:
> >
> >
> >>Hi,
> >>
> >>I am working on segmentation of AAA in CTimages.
> >>I found really intresting the file report "Active Shape
> >>Models_itk.ppt"
> >>in the InsightDocuments checkout. I tried to modified the
> >>itkImagePCAShapeModelEstimatorTest.cxx to see how it handles some
> >>training dataset but it always returns the last training image and
> >>the
> >>eigen values are all zero.
> >>
> >>I attach the code and the training images, any suggestion?
> >>Thanks in advance,
> >>
> >>Ilaria Canova Calori
> >>
> >>--
> >>
> >
> >
> >
> > --
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> >
> >
>
>
>
>
--
-------------- next part --------------
// Insight classes
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkLightProcessObject.h"
#include "itkImagePCAShapeModelEstimator.h"
int main(int argc, char *argv[] )
{
if( argc < 5 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " meanOutputFile firstPrincipalComponent secondPrincipalComponent ";
std::cerr << " MaxNumShape firstShapeModel second ... " <<std::endl;
return 1;
}
typedef unsigned char PixelType;
const unsigned int Dimension = 2;
const unsigned int NUMTRAINIMAGES = 3;
const unsigned int NUMLARGESTPC = 2;
typedef itk::Image<PixelType,Dimension> InputImageType;
typedef itk::Image<PixelType,Dimension> OutputImageType;
typedef itk::Image<PixelType,Dimension> MeanImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer1 = WriterType::New();
WriterType::Pointer writer2 = WriterType::New();
typedef itk::ImagePCAShapeModelEstimator<InputImageType, OutputImageType>
ImagePCAShapeModelEstimatorType;
ImagePCAShapeModelEstimatorType::Pointer
applyPCAShapeEstimator = ImagePCAShapeModelEstimatorType::New();
applyPCAShapeEstimator->SetNumberOfTrainingImages( NUMTRAINIMAGES );
applyPCAShapeEstimator->SetNumberOfPrincipalComponentsRequired( NUMLARGESTPC );
const unsigned int max = atoi( argv[4] );
for(unsigned int i=0; i<max; i++)
{
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[5+i] );
reader->Update();
InputImageType::Pointer image = InputImageType::New();
InputImageType::SizeType inputImageSize ;
inputImageSize = reader->GetOutput()->GetRequestedRegion().GetSize();
InputImageType::IndexType index;
index.Fill(0);
InputImageType::RegionType region;
region.SetSize( inputImageSize );
region.SetIndex( index );
image->SetLargestPossibleRegion( region );
image->SetBufferedRegion( region );
image->Allocate();
image = reader->GetOutput();
applyPCAShapeEstimator->SetInput(i, image);
}
applyPCAShapeEstimator->Update();
//Print the eigen vectors
vnl_vector<double> eigenValues = applyPCAShapeEstimator->GetEigenValues();
unsigned int numEigVal = eigenValues.size();
std::cout << "Number of returned eign-values: " << numEigVal << std::endl;
std::cout << "The " <<
applyPCAShapeEstimator->GetNumberOfPrincipalComponentsRequired() <<
" largest eigen values are:" << std::endl;
for(unsigned int i= 0; i< vnl_math_min( numEigVal, (unsigned int)NUMLARGESTPC ); i++ )
{
std::cout << eigenValues[ i ] << std::ends;
}
std::cout << "" << std::endl;
std::cout << "" << std::endl;
//Print the OutputImage
for ( unsigned int j=0; j<NUMLARGESTPC+1 ; j++)
{
OutputImageType::Pointer outImage = applyPCAShapeEstimator->GetOutput( j );
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[1+j]);
writer->SetInput(outImage);
writer->Update();
}
//Test for the eigen values for the test case precomputed using Matlab/Splus
std::cout << "" << std::endl;
if( (eigenValues[2] < 6 || eigenValues[2] > 6.1) || (eigenValues[1] >0.1) )
std::cout<< "Test Passed" << std::endl;
else
std::cout<< "Test failed" << std::endl;
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Lumen1.jpg
Type: image/pjpeg
Size: 2013 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20050110/1f2052db/Lumen1-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Lumen3.jpg
Type: image/pjpeg
Size: 2006 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20050110/1f2052db/Lumen3-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Lumen4.jpg
Type: image/pjpeg
Size: 2014 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20050110/1f2052db/Lumen4-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ASM1.jpg
Type: image/pjpeg
Size: 2013 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20050110/1f2052db/ASM1-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ASM2.jpeg
Type: image/pjpeg
Size: 1891 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20050110/1f2052db/ASM2-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ASM3.jpg
Type: image/pjpeg
Size: 1909 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20050110/1f2052db/ASM3-0001.bin
More information about the Insight-users
mailing list