active shape model avec C++ et ITK
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:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
#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::Pointer 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::Pointer dicomIO = DicomIOType::New();
// read 2D images and construct a volume
SeriesReaderType::Pointer seriesReader = SeriesReaderType::New();
NameGeneratorType::Pointer 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::Pointer 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::Pointer
ImageSearch = ImageSearchType::New();
const unsigned int m_LenghtOfProfile = 3;
const unsigned int m_NumberOfIteration = 2;
typedef itk::ImageFileReader< Image2DType > Reader2DType;
Reader2DType::Pointer 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;
} |