--- /dev/null
+#include <cstdlib>
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include <itkImage.h>
+#include <itkGDCMImageIO.h>
+#include <itkGDCMSeriesFileNames.h>
+#include <itkImageSeriesReader.h>
+#include <itkImageFileWriter.h>
+
+// -------------------------------------------------------------------------
+typedef short TPixel;
+const unsigned int Dim = 3;
+typedef itk::Image< TPixel, Dim > TImage;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+ if( argc < 3 )
+ {
+ std::cerr
+ << "Usage: " << std::endl
+ << argv[ 0 ] << " dicom_dir output_extension"
+ << std::endl;
+ return( 1 );
+
+ } // fi
+ std::string dicom_dir = argv[ 1 ];
+ std::string output_extension = argv[ 2 ];
+
+ typedef itk::GDCMSeriesFileNames TNameGenerator;
+ TNameGenerator::Pointer name_gen = TNameGenerator::New( );
+ name_gen->SetUseSeriesDetails( true );
+ name_gen->AddSeriesRestriction( "0008|0021" );
+ name_gen->SetDirectory( dicom_dir );
+ try
+ {
+ typedef std::vector< std::string > TSeriesIdContainer;
+ const TSeriesIdContainer& seriesUID = name_gen->GetSeriesUIDs( );
+
+ TSeriesIdContainer::const_iterator serieIt = seriesUID.begin( );
+ for( ; serieIt != seriesUID.end( ); ++serieIt )
+ {
+ // Get series identifier
+ std::string serieId = serieIt->c_str( );
+ std::cout
+ << "\nReading: "
+ << serieId << std::endl;
+
+ // Get filenames for actual serie
+ typedef std::vector< std::string > TFileNamesContainer;
+ TFileNamesContainer filenames;
+ filenames = name_gen->GetFileNames( serieId );
+
+ // Read image
+ itk::ImageSeriesReader< TImage >::Pointer reader =
+ itk::ImageSeriesReader< TImage >::New( );
+ itk::GDCMImageIO::Pointer dicomIO = itk::GDCMImageIO::New( );
+ reader->SetImageIO( dicomIO );
+ reader->SetFileNames( filenames );
+
+ // Write image
+ std::string serie_filename;
+ serie_filename = dicom_dir + "/" + serieId + "." + output_extension;
+
+ itk::ImageFileWriter< TImage >::Pointer writer =
+ itk::ImageFileWriter< TImage >::New( );
+ writer->SetFileName( serie_filename );
+ writer->UseCompressionOff( );
+ writer->SetInput( reader->GetOutput( ) );
+ std::cout << "Writing: " << serie_filename << std::endl;
+ try
+ {
+ writer->Update( );
+ }
+ catch( itk::ExceptionObject& err )
+ {
+ std::cerr << " Error caught: " << err << std::endl;
+
+ } // yrt
+
+ } // rof
+ }
+ catch( itk::ExceptionObject& err )
+ {
+ std::cerr << "Error caught: " << std::endl << err << std::endl;
+ return( 1 );
+
+ } // yrt
+ return( 0 );
+}
+
+// eof - $RCSfile$