Active shape model avec C++ et itk

Signaler
Messages postés
1
Date d'inscription
mardi 6 novembre 2007
Statut
Membre
Dernière intervention
23 novembre 2007
-
Messages postés
1054
Date d'inscription
samedi 2 octobre 2004
Statut
Membre
Dernière intervention
9 juillet 2013
-
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


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 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;

}

1 réponse

Messages postés
1054
Date d'inscription
samedi 2 octobre 2004
Statut
Membre
Dernière intervention
9 juillet 2013
7
Salut,
Place ton image à l'endroi des sources. Lorsque tu compiles avec Visual, il va les chercher la.

Par contre quand tu lancera ton exe depuis ton dossier debug, il va chercher ton image dans le meme dossier que celui de l'exe donc dans ton fichier debug

Mon site internet : http://pistol.petesampras.free.fr