Active shape model aec c++ et itk

Fermé
zalzali Messages postés 1 Date d'inscription vendredi 23 novembre 2007 Statut Membre Dernière intervention 23 novembre 2007 - 23 nov. 2007 à 01:36
 aam - 20 mars 2009 à 16:00
Bonjour,
j'essaye de programmer l'active shape model avec du c++, pour cela je fais appel aux classes itkactiveshapemodelcalculator, itkactiveshapemodelgradientsearch, mon programme compile bien, mais quand je l'execute, il me sort une exeption disant qu'il ne trouve pas l'image alors que l'image est mis dans le dossier debug.

vous pouvez trouvez mon code ici, et si vous voyez ce qui ne va pas, dites le moi svp:

#include "itkActiveShapeModelCalculator.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImageSeriesReader.h"
#include "itkNumericSeriesFileNames.h"
#include "itkBMPImageIO.h"
#include "itkPNGImageIO.h"
#include "itkArray.h"
#include "itkActiveShapeModelGradientSearchMethod.h"
#include <iostream>


using namespace std;


int main( int argc, char * argv[] )
{

typedef unsigned char InputPixelType;
typedef itk::Image < InputPixelType, 3 > InputVolumeType;
typedef itk::Image< unsigned char, 2 > Image2DType;


typedef itk::ImageFileReader<Image2DType> ReaderType;
ReaderType:ointer reader= ReaderType::New();

Image2DType::ConstPointer inputImage;
const char * filename = argv[1];
reader->SetFileName( filename );
reader->Update();

inputImage=reader->GetOutput();

typedef itk::ActiveShapeModelCalculator< InputVolumeType > ASMCalculatorType;
typedef itk::ImageSeriesReader< InputVolumeType > SeriesReaderType;
typedef itk::NumericSeriesFileNames NameGeneratorType;
//DicomIOType:ointer dicomIO = DicomIOType::New();

// read 2D images and construct a volume
SeriesReaderType:ointer seriesReader = SeriesReaderType::New();



NameGeneratorType:ointer nameGenerator = NameGeneratorType::New();
nameGenerator->SetSeriesFormat( filename);
//nameGenerator->

nameGenerator->SetStartIndex(1);
nameGenerator->SetEndIndex(2);
nameGenerator->SetIncrementIndex( 1 );
seriesReader->SetFileNames( nameGenerator->GetFileNames());
seriesReader->SetImageIO( itk::BMPImageIO::New() );

ASMCalculatorType:ointer asm_calculator = ASMCalculatorType::New();
try
{
seriesReader->Update();
}
catch ( itk::ExceptionObject & err )
{
cout << "Exception Object caught HNA!" << endl;
cerr << err << endl;
return EXIT_FAILURE;
}

asm_calculator->SetImage( seriesReader->GetOutput() );

try
{

asm_calculator->GenerateData();
}
catch ( itk::ExceptionObject & err )
{
std::cerr << "Exception Object caught!" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}

itk::Array<double> meanShape;

meanShape = asm_calculator->GetMeanShape();
vnl_vector<double> eigenValues = asm_calculator->GetEigenvalues();
vnl_matrix<double> eigenVectors = asm_calculator->GetEigenvector();

for ( unsigned int i=0; i<meanShape.GetNumberOfElements(); i++ )
{
std::cout << i << ": " << meanShape.GetElement(i) << std::endl;
}


//Print the eigen values and eigen vectors
std::cout << "Vecteurs Propres:" << std::endl;

for(unsigned int i = 0; i < eigenVectors.rows(); i++)
{
std::cout<< eigenVectors.get_row(i)<<" ";
} std::cout <<""<<std::endl;

cout << "Valeurs Propres:" << endl;
cout << eigenValues << endl;


typedef itk::ActiveShapeModelGradientSearchMethod< Image2DType> ImageSearchType;
ImageSearchType:ointer
ImageSearch = ImageSearchType::New();
const unsigned int m_LenghtOfProfile = 3;
const unsigned int m_NumberOfIteration = 2;
typedef itk::ImageFileReader< Image2DType > Reader2DType;
Reader2DType:ointer reader1 = Reader2DType::New();

const char * input2DFilename = argv[2];
reader1->SetFileName( input2DFilename );
reader1->Update( );
ImageSearch->SetImage( reader1->GetOutput() );


//----------------------------------------------------------------------
//Set the parameters ActiveShapeModelSearchingImageFilter
//----------------------------------------------------------------------
ImageSearch->SetLenghtOfProfile( m_LenghtOfProfile );
ImageSearch->SetNumberOfIteration( m_NumberOfIteration );
ImageSearch->SetMeanShape( asm_calculator->GetMeanShape() + 0.5);
ImageSearch->SetEigenValues( asm_calculator->GetEigenvalues() );
ImageSearch->SetEigenVectors( asm_calculator->GetEigenvector() );
cout<<"hani hna"<<endl;

ImageSearch->GenerateData();

cout<<"hani hna2"<<endl;
//Test the printself function to increase coverage
ImageSearch->Print(std::cout);

//Exercise TypeMacro in superclass
typedef ImageSearchType::Superclass GenericEstimator2Type;
std::cout << ImageSearch->GenericEstimator2Type::GetNameOfClass() << std::endl;


cout << "The new shape: " <<

ImageSearch->GetNewShape() <<endl;


// Software Guide : BeginCodeSnippet
// Software Guide : EndCodeSnippet


return EXIT_SUCCESS;

}

2 réponses

Mais, où est ce que t'a appris à programmer?!

A part, il faut mettre l'image dans le dossier du projet quand vous testé le pgm à partir de l'environnment c++, pas dans debug.
0
salut
tu as pensé à partager to application "active shape model aec c++ et itk" avec les autres
ça m'intéresse qu'elle sera publiée sur le net
merci de me le communiquer
0