[vtkusers] Reading different series images from a single dicom folder
ghy
ghy at tellyes.com
Mon Feb 17 04:13:32 EST 2014
I used to using ITK to read DICOM series Images in this case. You can know
how much series in the directory and can select a series to read.
Good Luck.
Susan.
Bellow is a code example:
#include "itkImageSeriesReader.h"
#include "itkDICOMImageIO2.h"
#include "itkDICOMSeriesFileNames.h"
#include "itkImageFileWriter.h"
int main( int argc, char* argv[] )
{
if( argc < 3 )
{
std::cerr << "Usage: " << argv[0] << " DicomDirectory outputFileName
[seriesName]" << std::endl;
return EXIT_FAILURE;
}
typedef itk::Image<short,3> ImageType;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
itk::DICOMImageIO2::Pointer dicomIO = itk::DICOMImageIO2::New();
// Get the DICOM filenames from the directory
itk::DICOMSeriesFileNames::Pointer nameGenerator =
itk::DICOMSeriesFileNames::New();
nameGenerator->SetDirectory( argv[1] );
try
{
typedef std::vector<std::string> seriesIdContainer;
const seriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
seriesIdContainer::const_iterator seriesItr = seriesUID.begin();
seriesIdContainer::const_iterator seriesEnd = seriesUID.end();
std::cout << std::endl << "The directory: " << std::endl;
std::cout << std::endl << argv[1] << std::endl << std::endl;
std::cout << "Contains the following DICOM Series: ";
std::cout << std::endl << std::endl;
while( seriesItr != seriesEnd )
{
std::cout << seriesItr->c_str() << std::endl;
seriesItr++;
}
std::cout << std::endl << std::endl;
std::cout << "Now reading series: " << std::endl << std::endl;
typedef std::vector<std::string> fileNamesContainer;
fileNamesContainer fileNames;
if( argc < 4 ) // If no optional third argument
{
std::cout << seriesUID.begin()->c_str() << std::endl;
fileNames = nameGenerator->GetFileNames();
}
else
{
std::cout << argv[3] << std::endl;
fileNames = nameGenerator->GetFileNames( argv[3] );
}
std::cout << std::endl << std::endl;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileNames( fileNames );
reader->SetImageIO( dicomIO );
try
{
reader->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
std::cout << "Writing the image as " << std::endl << std::endl;
std::cout << argv[2] << std::endl << std::endl;
writer->SetFileName( argv[2] );
writer->SetInput( reader->GetOutput() );
try
{
writer->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex;
return EXIT_FAILURE;
}
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/Reading-different-series-images-from-a-single-dicom-folder-tp5725959p5725961.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list