[Insight-users] Re: what's the problem xith my code : Active Shape Model

Luis Ibanez luis.ibanez at kitware.com
Mon Nov 26 15:11:28 EST 2007


Hi Amine,

I just tested your code, and the part that reads the BMP file works fine
for me, as long as I copy the .bmp file at the root of the C: drive.

It seems that you are not placing the file named "130.bmp" at the top
level of your C: drive.

Please make sure that you copy that file in the top level
of your C: disk.

----

Also, looking at your code, you seem to be misusing the series reader,
because you are passing to it a single 2D image, while, in practice
you usually want to use it for reading a group of 2D images.


Passing a single 2D image for the active shape model calculator
doesn't makes much sense either...


Normally you would have something like a collection of 20 images,
named:

    000.bmp
    001.bmp
    002.bmp
    003.bmp
...
    018.bmp
    019.bmp


and what you are expected to pass to the series reader is:


 > nameGenerator->SetSeriesFormat( "c:\\%03d.bmp" );
 > nameGenerator->SetStartIndex( 0 );
 > nameGenerator->SetEndIndex( 19 );
 > nameGenerator->SetIncrementIndex( 1 );



Note that "SeriesFormat" is expecting a format like the one
that you will use in a printf() or a scanf() function.

Note also that if you find inconvenient to put the image data
at the top level of the C: drive, you can actually pass a specific
directory as part of the format. For example, you could place
your collection of images in a directory called:

    C:\Amine\Data\

and pass a SeriesFormat such as:


 > nameGenerator->SetSeriesFormat( "c:/Amine/Data/%03d.bmp" );






     Regards,



         Luis



---------------------
amine kabous wrote:
> 
>     Hello,
>      
>     i want to use active shape model for segmentation of medical Image 2d.
> 
> for construction a volume itk::ImageSeriesReader. the program compile fine, but it crash in run time, it tell me that   BMPImageIO could not open file c:\130.bmp for reading.
> 
> please find my program, and if you have any suggestion or if you fond any error, tell it to me
> 
> Thanks
> 
>  
> 
> #include "itkActiveShapeModelCalculator.h"
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImageSeriesReader.h"
> #include "itkNumericSeriesFileNames.h"
> #include "itkBMPImageIO.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::ActiveShapeModelCalculator< InputVolumeType > ASMCalculatorType;
> typedef itk::ImageSeriesReader< InputVolumeType > SeriesReaderType;
> typedef itk::NumericSeriesFileNames NameGeneratorType;
> 
> 
> SeriesReaderType::Pointer seriesReader = SeriesReaderType::New();
> 
> 
> NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
> 
> nameGenerator->SetSeriesFormat( "c:\\130.bmp" );
> 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 )
> {
> std::cerr << "Exception Object caught!" << std::endl;
> std::cerr << err << std::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;
> }
> 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() );
> 
> 
> 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() );
> 
> ImageSearch->GenerateData();
> ImageSearch->Print(std::cout);
> typedef ImageSearchType::Superclass GenericEstimator2Type;
> std::cout << ImageSearch->GenericEstimator2Type::GetNameOfClass() << std::endl;
> 
> cout << "The new shape: " <<
> ImageSearch->GetNewShape() <<endl;
> 
> 
> 
> 
> 
> return EXIT_SUCCESS;
> 
> }
> 
> 
> ------------------------------------------------------------------------
> Appelez vos amis de PC à PC -- C'EST GRATUIT Essayez-le maintenant ! 
> <http://get.live.com/messenger/overview>
> ------------------------------------------------------------------------
> 


More information about the Insight-users mailing list