From: Leonardo Florez-Valencia Date: Wed, 9 Sep 2015 16:10:08 +0000 (+0200) Subject: ... X-Git-Tag: v0.1~388 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=5fdf6b8c7d045d2945550b413691e5cb13e268b3;p=cpPlugins.git ... --- diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index d2165fe..97801d4 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -29,6 +29,7 @@ ENDFOREACH(prog) SET( NOPLUGINS_EXAMPLES_PROGRAMS + example_ExtractDICOMSeries example_ImageGaussianModelEstimator example_ReadQuadEdgeMeshWithoutPlugins example_RenderQuadEdgeMeshWithoutPlugins diff --git a/appli/examples/example_ExtractDICOMSeries.cxx b/appli/examples/example_ExtractDICOMSeries.cxx new file mode 100644 index 0000000..a885c9b --- /dev/null +++ b/appli/examples/example_ExtractDICOMSeries.cxx @@ -0,0 +1,94 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +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$