[Insight-users] Changing a DICOM Header... in a DICOM Series

Stéphane CALANDE scalande at gmail.com
Wed Nov 19 09:17:27 EST 2008


Martin, you were very helpful !


I give the solution :



  typedef signed short    PixelType;
  const unsigned int      Dimension = 3;
  typedef itk::Image< PixelType, Dimension >      ImageType;
  typedef itk::ImageSeriesReader< ImageType >     ReaderType;
  typedef itk::ImageFileReader< ImageType >       ReaderMHDType;
  typedef itk::GDCMImageIO                        ImageIOType;
  typedef itk::GDCMSeriesFileNames                NamesGeneratorType;

  ImageIOType::Pointer gdcmIO = ImageIOType::New();
  NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();

  namesGenerator->SetInputDirectory( [...DIRECTORY...] );

  const ReaderType::FileNamesContainer & filenames =
                            namesGenerator->GetInputFileNames();

  ReaderType::Pointer reader = ReaderType::New();

  reader->SetImageIO( gdcmIO );
  reader->SetFileNames( filenames );

  reader->Update();

  *// BEGIN IMPORTANT CODE*

*  unsigned int nbSlices = filenames.size();

  ReaderType::DictionaryRawPointer dictionary[nbSlices];
  ReaderType::DictionaryArrayType outputArray;

  for (unsigned int i = 0; i < nbSlices; i++)
    {
    dictionary[i] = (*(reader->GetMetaDataDictionaryArray()))[i];

    std::string entryId("0008|103e");
    std::string value("MARTIN IS THE BEST"); *// it was just a test ;-)*
    itk::EncapsulateMetaData<std::string>( *dictionary[i], entryId, value
);
    outputArray.push_back(dictionary[i]);
    }  *

   *// END*

    [...]

  typedef signed short    OutputPixelType;
  const unsigned int      OutputDimension = 2;

  typedef itk::Image< OutputPixelType, OutputDimension >    Image2DType;

  typedef itk::ImageSeriesWriter< ImageType, Image2DType >
SeriesWriterType;

  SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();

  seriesWriter->SetInput( [...VOLUME...] );
  seriesWriter->SetImageIO( gdcmIO );

  namesGenerator->SetOutputDirectory( outputDirectory );

  seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );

  *// BEGIN IMPORTANT CODE*
  *seriesWriter->SetMetaDataDictionaryArray( &outputArray );*
  // instead of :
  // seriesWriter->SetMetaDataDictionaryArray(
reader->GetMetaDataDictionaryArray() );
*  // END*

  seriesWriter->Update();





Thank you again Martin ;-)




Stéphane






2008/11/19 Martin Kavec <martin.kavec at gmail.com>

> Stephane,
>
> I was on the same issue two days ago with the same results. The problem is
> that each slice in your input series has unique MetaDataDictionary, so you
> have to change the field you desire in all of them.
>
> I have found in the ITK mailing list archives a post from Bill (I guess)
> where
> he send attached a file DicomResample which does what you need. Just google
> for DicomResample and the very first reference is what you need.
>
> Regards,
>
> Martin
>
> On Wednesday 19 November 2008 13:38:06 Stéphane CALANDE wrote:
> > Oh sorry, there was a mistake in the entry...
> >
> > But the field is still not modified... :-(
> >
> >
> > Any other idea ?
> >
> >
> > Thank you Bill ;-)
> >
> >
> >
> >
> > Stéphane
> >
> >
> >
> >
> > 2008/11/19 Bill Lorensen <bill.lorensen at gmail.com>
> >
> > > Try
> > >  std::string entryId("0008|103e");
> > > instead of
> > >  std::string entryId("008|103e");
> > >
> > > Bill
> > >
> > > On Wed, Nov 19, 2008 at 6:53 AM, Stéphane CALANDE <scalande at gmail.com>
> > >
> > > wrote:
> > > > Hi itk-list,
> > > >
> > > >
> > > > I'm using the example of "DicomSeriesReadSeriesWrite", but I'd like
> to
> > > > modify one DICOM header field before writing the Series.
> > > >
> > > > Then I had a look in "DicomImageReadChangeHeaderWrite" and I tried to
> > >
> > > apply
> > >
> > > > the part of the code that change the header field into the code of
> > > > "DicomSeriesReadSeriesWrite".
> > > >
> > > >
> > > > But it doesn't seem to work. The field I want to change has not
> changed
> > >
> > > in
> > >
> > > > the output files. Could you have a look in the (simplified) following
> > >
> > > code
> > >
> > > > to help me ?
> > > >
> > > >
> > > >
> > > >   typedef signed short    PixelType;
> > > >   const unsigned int      Dimension = 3;
> > > >   typedef itk::Image< PixelType, Dimension >      ImageType;
> > > >   typedef itk::ImageSeriesReader< ImageType >     ReaderType;
> > > >   typedef itk::ImageFileReader< ImageType >       ReaderMHDType;
> > > >   typedef itk::GDCMImageIO                        ImageIOType;
> > > >   typedef itk::GDCMSeriesFileNames                NamesGeneratorType;
> > > >
> > > >   ImageIOType::Pointer gdcmIO = ImageIOType::New();
> > > >   NamesGeneratorType::Pointer namesGenerator =
> > > > NamesGeneratorType::New();
> > > >
> > > >   namesGenerator->SetInputDirectory( [...DIRECTORY...] );
> > > >
> > > >   const ReaderType::FileNamesContainer & filenames =
> > > >                             namesGenerator->GetInputFileNames();
> > > >
> > > >   ReaderType::Pointer reader = ReaderType::New();
> > > >
> > > >   reader->SetImageIO( gdcmIO );
> > > >   reader->SetFileNames( filenames );
> > > >
> > > >   reader->Update();
> > > >
> > > >   // BEGIN => I'm trying to modify one DICOM Header field <<<
> > > >
> > > >   typedef itk::MetaDataDictionary   DictionaryType;
> > > >
> > > >   ImageType::Pointer inputImage = reader->GetOutput();
> > > >   DictionaryType & dictionary = inputImage->GetMetaDataDictionary();
> > > >
> > > >   std::string entryId("008|103e");
> > > >   std::string value("NEW VALUE");
> > > >
> > > >   itk::EncapsulateMetaData<std::string>( dictionary, entryId, value
> );
> > > >
> > > >    // END
> > > >
> > > >     [...]
> > > >
> > > >   typedef signed short    OutputPixelType;
> > > >   const unsigned int      OutputDimension = 2;
> > > >
> > > >   typedef itk::Image< OutputPixelType, OutputDimension >
> > > > Image2DType;
> > > >
> > > >   typedef itk::ImageSeriesWriter< ImageType, Image2DType >
> > > > SeriesWriterType;
> > > >
> > > >   SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
> > > >
> > > >   seriesWriter->SetInput( [...VOLUME...] );
> > > >   seriesWriter->SetImageIO( gdcmIO );
> > > >
> > > >   namesGenerator->SetOutputDirectory( outputDirectory );
> > > >
> > > >   seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );
> > > >
> > > >   seriesWriter->SetMetaDataDictionaryArray(
> > > >                         reader->GetMetaDataDictionaryArray() );
> > > >
> > > >   seriesWriter->Update();
> > > >
> > > >
> > > >
> > > >
> > > > I would be very grateful if you could help me.
> > > >
> > > >
> > > > Thank you very much,
> > > >
> > > >
> > > >
> > > > Stéphane
> > > >
> > > > _______________________________________________
> > > > Insight-users mailing list
> > > > Insight-users at itk.org
> > > > http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20081119/b3cc115c/attachment-0001.htm>


More information about the Insight-users mailing list