[Insight-users] DICOM TO RAW

田光建 gjtian at hotmail.com
Wed Jul 16 09:47:54 EDT 2008


Dear ALL,
I want to convert DICOM image into raw format,I use amide to display my image. Before the format transformation, the DICOM image can be displayed in amide correctly, but after the format transformation, the patient's head will be in bottom in raw data displyed in amide. The following are the source codes:
 
#if defined(_MSC_VER)#pragma warning ( disable : 4786 )#pragma warning ( disable : 4996)#endif
 
#include "itkImage.h"
#include "itkOrientedImage.h"#include "itkGDCMImageIO.h"#include "itkGDCMSeriesFileNames.h"#include "itkImageSeriesReader.h"#include "itkImageFileWriter.h"
int main( int argc, char *argv[] ){    const    unsigned int    ImageDimension = 3;    typedef  signed short    PixelType;
    typedef itk::Image< PixelType, ImageDimension >  ImageType;
    typedef itk::OrientedImage< PixelType, ImageDimension  > ImageReaderType;
    typedef itk::ImageSeriesReader< ImageReaderType >        ReaderType;
    ReaderType::Pointer  ImageReader  = ReaderType::New();
    typedef itk::GDCMImageIO       ImageIOType;    ImageIOType::Pointer dicomIO = ImageIOType::New();
    ImageReader->SetImageIO( dicomIO );
    typedef itk::GDCMSeriesFileNames NamesGeneratorType;    NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
    nameGenerator->SetUseSeriesDetails( true );    nameGenerator->AddSeriesRestriction("0008|0021" );
    nameGenerator->SetDirectory( argv[1] );
    typedef std::vector< std::string >    SeriesIdContainer;
    const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
    SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();    SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();    while( seriesItr != seriesEnd )    {        std::cout << "input image series:" << std::endl;        std::cout << seriesItr->c_str() << std::endl;        seriesItr++;    }
    std::string seriesIdentifier;
    seriesIdentifier = seriesUID.begin()->c_str();
    std::cout << std::endl << std::endl;    std::cout << "Now reading series: " << std::endl << std::endl;    std::cout << seriesIdentifier << std::endl;    std::cout << std::endl << std::endl;
    typedef std::vector< std::string >   FileNamesContainer;    FileNamesContainer ImagefileNames;
    ImagefileNames = nameGenerator->GetFileNames( seriesIdentifier );
    ImageReader->SetFileNames(ImagefileNames);
    ImageType::ConstPointer inputImage = ImageReader->GetOutput();
    try    {        ImageReader->Update();    }    catch (itk::ExceptionObject &err)    {        std::cerr << "ExceptionObject caught !" << std::endl;         std::cerr << err << std::endl;         return EXIT_FAILURE;    }
    typedef itk::ImageFileWriter< ImageType > ImageFileWriterType;
    ImageFileWriterType::Pointer writer = ImageFileWriterType::New();
    writer->SetInput( inputImage );
    writer->SetFileName( argv[2] );
    try    {        writer->Update();    }    catch (itk::ExceptionObject &err)    {        std::cerr << "ExceptionObject caught !" << std::endl;         std::cerr << err << std::endl;         return EXIT_FAILURE;    }
    return EXIT_SUCCESS;}
_________________________________________________________________
这里好多好玩的视频,用鼠标点到视频看看,有惊喜!
http://cnweb.search.live.com/video/results.aspx?q=%E5%A5%A5%E8%BF%90%E5%9C%A3%E7%81%AB&mkt=zh-cn&FORM=WLMTWC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080716/5798150a/attachment.htm>


More information about the Insight-users mailing list