[Insight-users] ImageSeriesReadWrite only reads first file.

Emma Ryan eryanvtk at yahoo.com
Tue Jun 12 03:16:53 EDT 2007



Hi,

  I am trying to generate a .vtk file (3D ) from a  set of .png images. I use the ImageSeriesReadWrite.cxx example provided in ITK as is. My command line syntax is  "SeriesRW.exe 0 31 output.vtk" 

i.e SeriesRW is the executable, there are 32 slices starting from 0, and the output format is supposed to be .vtk , so that I can open it using Volview.

While the program executes with no errors or warnings, when I open output.vtk file in Volview, it seems to be empty.

I am not sure why this.  If anyone has a clue as to why
 this happens, please let me know.  Here is the code.

#include "itkImage.h"
#include "itkImageSeriesReader.h"
#include "itkImageFileWriter.h"
#include "itkNumericSeriesFileNames.h"
#include "itkPNGImageIO.h"


int main( int argc, char ** argv )
{
  
  if( argc < 4 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " firstSliceValue lastSliceValue  outputImageFile " << std::endl;
    return EXIT_FAILURE;
    }


  typedef unsigned char                       PixelType;
  const unsigned int Dimension = 3;

  typedef itk::Image< PixelType, Dimension >  ImageType;

  typedef itk::ImageSeriesReader< ImageType
 >  ReaderType;
  typedef itk::ImageFileWriter<   ImageType >  WriterType;

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

  const unsigned int first = atoi( argv[1] );
  const unsigned int last  = atoi( argv[2] );

  const char * outputFilename = argv[3];


  typedef itk::NumericSeriesFileNames    NameGeneratorType;

  NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();


  nameGenerator->SetSeriesFormat( "file%03d.png" );

  nameGenerator->SetStartIndex( first);
  nameGenerator->SetEndIndex( last );
  nameGenerator->SetIncrementIndex( 1 );



  reader->SetImageIO( itk::PNGImageIO::New() );

 reader->SetFileNames( nameGenerator->GetFileNames()  );


 
 writer->SetFileName( outputFilename );

  writer->SetInput( reader->GetOutput() );

  try 
    { 
    writer->Update(); 
    } 
  catch( itk::ExceptionObject & err ) 
    { 
    std::cerr << "ExceptionObject caught !" << std::endl; 
    std::cerr << err << std::endl; 
    return EXIT_FAILURE;
    } 


  return EXIT_SUCCESS;
}


Thank you,
Emma




      Building a website is a piece of cake. 
Yahoo! Small Business gives you all the tools to get online.







Don't get soaked.  Take a quick peak at the forecast 
 with theYahoo! Search weather shortcut.





       
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070612/37f3f687/attachment.htm


More information about the Insight-users mailing list