[Insight-users] Cannot Read ImageSeries and save as 3D Volume

agatte wiatrak11 at poczta.onet.pl
Fri Jul 20 08:57:16 EDT 2012


Hi All ;)

I am trying to read image series and save as a Volume.
But I wantn't   to set fixed first and last image. 
Size depends on the Image Series.
I used this example :
http://www.itk.org/Wiki/ITK/Examples/IO/VolumeFromSlices

I have already modified this code  but it is going wrong ;/

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

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

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

  reader->SetImageIO( itk::TIFFImageIO::New() );
  
  ImageType::ConstPointer  volume = reader->GetOutput();
  ImageType::RegionType volumeRegion = volume->GetLargestPossibleRegion();
  ImageType::IndexType start = volumeRegion.GetIndex();
  ImageType::SizeType size = volumeRegion.GetSize();

  const unsigned int firstImage = start[2];
  const unsigned int lastImage  = start[2] + size[2] - 1;

  const char * outputFilename = "volume3Dtest.vtk";

  typedef itk::NumericSeriesFileNames    NameGeneratorType;
  NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
  nameGenerator->SetSeriesFormat( "C:\\data\\series\\File%03d.tiff" );

  nameGenerator->SetStartIndex( firstImage );
  nameGenerator->SetEndIndex( lastImage );

  // take every two/second image
  nameGenerator->SetIncrementIndex(2);

 reader->SetImageIO( itk::TIFFImageIO::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;
}


I would appreciate for any help please.


Best,
agatte
-- 
View this message in context: http://old.nabble.com/Cannot-Read-ImageSeries-and-save-as-3D-Volume-tp34189755p34189755.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list