[Insight-users] Writing DICOM files, code attached

Luis Ibanez luis.ibanez at kitware.com
Thu Apr 19 16:16:23 EDT 2007


Hi Invisible Human

You should be able to create DICOM files out of an existing
itkImage, regardless of how that image was read.

Of course when the original image file format is DICOM,
there is some interest to carry the DICOM tags along to
the image that is being written.

In your case, however, ITK (via GDCM) should create a compliant
DICOM header.

In order to write compressed DICOM you should invoke the
method SetCompressionOn() in the GDCMImageIO object, and
you should as well select among the two compression options
that GDCM supports:

   * JPEG
   * JPEG2000

You should use one of these two enums as arguments to the
method SetCompressionType().


Since you are observing that the DICOM file is not being
write correctly, you may want to do the following first:


1) Save the image in a standard format such as MetaImage,
    VTK or Analyze.

2) Use the ImageViewer application that is distributed with
    InsightApplications for visually verifying the content
    of the image that you saved in (1).
    You can get binaries of this application at
    http://public.kitware.com/pub/itk/InsightApplicationsBin/


3) Once you get (2) to work, then you can try again
    writing the DICOM image. At that point you should
    verify the tags using an application such as MRICro.





     Regards,


        Luis


--------------------------
Invisible Human wrote:
> Hi Luis,
> 
> Thank you for the response.
> 
> If you notice, the reader is reading raw data, not dcm data so there is no meta data dictionary.
> 
> Is there an example of how to write raw data as compressed dicom?  If not as compressed dicom, is there another way to write raw data as JPEG2000 compressed data?
> 
> Thanks,
> 
> IH.
> 
> ----- Original Message ----
> From: Luis Ibanez <luis.ibanez at kitware.com>
> To: Invisible Human <itk_at_stanford at yahoo.com>
> Cc: Insight Users <insight-users at itk.org>
> Sent: Sunday, April 15, 2007 7:33:44 PM
> Subject: Re: [Insight-users] Writing DICOM files, code attached
> 
> 
> 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
>>
> 
> 
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> 


More information about the Insight-users mailing list