Fourth, read a series of dcm picture, and then re-write

First, the program features

  Read a series of CT dcm picture, and then re-written to a folder

Second, the code

  

#pragma warning (disable: 4996) 
#include " itkGDCMImageIO.h "  
#include " itkGDCMSeriesFileNames.h "  
#include " itkImageSeriesReader.h "  
#include " itkImageSeriesWriter.h " 

int main ( int argc, char ** the argv) 
{ 
    // defines the pixel type, image type, three-dimensional signed number, definition of a pointer 
    typedef signed Short PixelType;
     const unsigned int the Dimension = . 3 ; 
    typedef image ITK :: <PixelType, the Dimension>ImageType; 
    typedef itk :: ImageSeriesReader <ImageType> ReaderType; 

    // statement read, write DICOM images itk :: GDCMImageIO objects
     // ITK :: GDCMSeriesFileNames object will generate and constitute a slice of all volume data file name sorting 
    typedef itk GDCMImageIO ImageIOType ::; 
    typedef ITK :: GDCMSeriesFileNames NamesGeneratorType; 
    ImageIOType the Pointer gdcmIO :: = ImageIOType :: New (); 
    NamesGeneratorType the Pointer namesGenerator :: = NamesGeneratorType :: New (); 

    // set the read path
     // occurs with a file name generated file name is read and written by the file name 
    namesGenerator-> SetInputDirectory ( " D: \\ files \\ ITKFiles ITK_5_ReadSeriesDCM \\ \\ \\ InputData the Data " );
    const ReaderType :: FileNamesContainer & namesGenerator- filenames => GetInputFileNames (); 

    // set list of DICOM image and file IO object name is read 
    ReaderType Pointer Reader :: = ReaderType :: New (); 
    Reader -> SetImageIO (gdcmIO); 
    Reader -> SetFileNames (of the filenames);
     the try 
    { 
        Reader -> the Update (); 
    } 
    the catch (ITK :: & ExceptionObject EX) 
    { 
        STD :: COUT << << EX STD :: endl;
         return EXIT_FAILURE; 
    } 
    // get the output directory name 
    const  charOutputDirectory = * " D: \\ Files \\ ITKFiles the Data \\ \\ \\ ITK_5_ReadSeriesDCM OutputData " ;
     // if the directory
     // does not already exist, we chose to create a directory. 
    :: :: MakeDirectory SystemTools itksys (the outputDirectory); 

    // instantiate program written image 
    typedef Signed Short OutputPixelType;
     const unsigned int OutputDimension = 2 ; 
    typedef Image ITK :: <OutputPixelType, OutputDimension> Image2DType; 
    typedef ImageSeriesWriter ITK :: <ImageType , Image2DType> SeriesWriterType; 

    // we create a sequence of images writer and connect the output from the writer to the reader's input. Then we pass GDCM
    //图像IO对象以便能用DICOM格式写这个图像。
    SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
    seriesWriter->SetInput(reader->GetOutput());
    seriesWriter->SetImageIO(gdcmIO);

    namesGenerator->SetOutputDirectory(outputDirectory);
    seriesWriter->SetFileNames(namesGenerator->GetOutputFileNames());
    seriesWriter->SetMetaDataDictionaryArray(reader->GetMetaDataDictionaryArray());
    try
    {
        seriesWriter->Update();
    }
    catch (itk::ExceptionObject& excp)
    {
        std::cerr << "Exception thrown while writing the series " << std::endl;
        std::cerr << excp << std::endl;
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}

 Third, pay attention

  The first sentence is grammatical in now because some do not meet specifications, but just be a warning rather than an error

Fourth, bibliography

  "Medical image segmentation and processing" ITK manual (ie manual ITK software, official website)

Guess you like

Origin www.cnblogs.com/fantianliang/p/11986660.html