[Insight-users] Writing DICOM files, code attached

Luis Ibanez luis.ibanez at kitware.com
Sun Apr 15 10:33:44 EDT 2007


Hi Invisible Human,

You seem to be missing the passing of the MetaDataDictionary
from the reader to the dcmWriter.

Please read the ITK Software Guide

     http://www.itk.org/ItkSoftwareGuide.pdf

In particular Section 7.12 "Reading and Writing DICOM Files",
in pdf-page 326-345.

You should pay particular attention to section 7.12.4, in
pdf-page 334.


The associated source code example can be found at

       Insight/Examples/IO/
          DicomSeriesReadSeriesWrite.cxx



   Regards,


      Luis



-------------------------
Invisible Human wrote:
> Hi,
> 
> The following code outputs the raw volume correctly but the dicom volume is garbage although there are no exceptions or errors.  Any pointers on whats lacking in this code will be appreciated.
> 
> Thanks,
> 
> Invisible Human.
> 
> 
> 
> -------------------------------------------------------------
> 
> void main(void){
> 
>     typedef unsigned short PixelType;
>     const unsigned int Dimension = 3;
>     typedef itk::Image<PixelType,Dimension> ImageType;
>     const unsigned int      OutputDimension = 2;
> 
>     typedef itk::Image< PixelType, OutputDimension >    Image2DType;
>     typedef itk::ImageSeriesWriter<ImageType, Image2DType > SeriesWriterType;
>     typedef itk::ImageFileWriter<ImageType> WriterType;
>     typedef itk::ImageSeriesReader<ImageType> ReaderType;
>     typedef itk::RawImageIO<PixelType,2> RawImageIOType;
>     typedef itk::RawImageIO<PixelType,3> Raw3DImageIOType;
>     typedef itk::GDCMImageIO                        GDCMIOType;
>     typedef itk::GDCMSeriesFileNames                NamesGeneratorType;
>     typedef itk::NumericSeriesFileNames NameGeneratorType;
> 
>     NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
>     nameGenerator->SetSeriesFormat( "C:\\VolData\\2.99.3915.a%03d" );
>     nameGenerator->SetStartIndex( 0 );
>     nameGenerator->SetEndIndex( 874 );
>     nameGenerator->SetIncrementIndex( 1 );
> 
>     ReaderType::Pointer reader = ReaderType::New();
>     reader->SetImageIO(rawIO);
>     reader->SetFileNames(nameGenerator->GetFileNames());
> 
>     GDCMIOType::Pointer gdcmIO = GDCMIOType::New();
>     gdcmIO->SetNumberOfComponents(1);
>     gdcmIO->SetDimensions(0,512);
>     gdcmIO->SetDimensions(1,512);
>     gdcmIO->SetDimensions(2,874);
> 
>     RawImageIOType::Pointer rawIO = RawImageIOType::New();
>     rawIO->SetDimensions(0,512);
>     rawIO->SetDimensions(1,512);
>     rawIO->SetFileTypeToBinary();
>     rawIO->SetByteOrderToBigEndian();
> 
>     Raw3DImageIOType::Pointer raw3DIO = Raw3DImageIOType::New();
>     raw3DIO->SetDimensions(0,512);
>     raw3DIO->SetDimensions(1,512);
>     raw3DIO->SetDimensions(2,874);
>     raw3DIO->SetFileTypeToBinary();
>     raw3DIO->SetByteOrderToBigEndian();
> 
>     WriterType::Pointer dcmWriter = WriterType::New();
>     dcmWriter = WriterType::New();
>     dcmWriter->SetFileName("c:\\temp\\dpitk\\test.dcm");
>     dcmWriter->SetInput(reader->GetOutput());
>     dcmWriter->SetImageIO(gdcmIO);
> 
>     WriterType::Pointer rawWriter = WriterType::New();
>     rawWriter = WriterType::New();
>     rawWriter->SetFileName("c:\\temp\\dpitk\\test.raw");
>     rawWriter->SetInput(reader->GetOutput());
>     rawWriter->SetImageIO(raw3DIO);
> 
>     try{
>         reader->Update();
>         dcmWriter->Update();
>         rawWriter->Update();
>     }
>     catch(itk::ExceptionObject& e){
>         std::cerr << "Error reading the series " << std::endl;
>         std::cerr << e << std::endl;
>     }
> }
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 


More information about the Insight-users mailing list