Martin, you were very helpful !<br><br><br>I give the solution :<br><br><br><br><font face="courier new,monospace"> typedef signed short PixelType;<br>
const unsigned int Dimension = 3;<br> typedef itk::Image< PixelType, Dimension > ImageType;<br> typedef itk::ImageSeriesReader< ImageType > ReaderType;<br> typedef itk::ImageFileReader< ImageType > ReaderMHDType;<br>
typedef itk::GDCMImageIO ImageIOType;<br> typedef itk::GDCMSeriesFileNames NamesGeneratorType; <br><br> ImageIOType::Pointer gdcmIO = ImageIOType::New();<br> NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();<br>
<br> namesGenerator->SetInputDirectory( [...DIRECTORY...] );<br><br> const ReaderType::FileNamesContainer & filenames = <br> namesGenerator->GetInputFileNames();<br> <br> ReaderType::Pointer reader = ReaderType::New();<br>
<br> reader->SetImageIO( gdcmIO );<br> reader->SetFileNames( filenames );<br><br> reader->Update();<br><br> <b>// BEGIN IMPORTANT CODE</b><br> <br><b> unsigned int nbSlices = filenames.size();<br> <br> ReaderType::DictionaryRawPointer dictionary[nbSlices]; <br>
ReaderType::DictionaryArrayType outputArray; <br> <br> for (unsigned int i = 0; i < nbSlices; i++)<br> { <br> dictionary[i] = (*(reader->GetMetaDataDictionaryArray()))[i]; <br><br> std::string entryId("0008|103e");<br>
std::string value("MARTIN IS THE BEST"); </b>// it was just a test ;-)<b><br> itk::EncapsulateMetaData<std::string>( *dictionary[i], entryId, value ); <br> outputArray.push_back(dictionary[i]);<br>
} </b><br> <br> <b>// END</b><br> <br> [...]<br> <br> typedef signed short OutputPixelType;<br> const unsigned int OutputDimension = 2;<br>
<br> typedef itk::Image< OutputPixelType, OutputDimension > Image2DType;<br><br> typedef itk::ImageSeriesWriter< ImageType, Image2DType > SeriesWriterType;<br><br> SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();<br>
<br> seriesWriter->SetInput( [...VOLUME...] );<br> seriesWriter->SetImageIO( gdcmIO );<br><br> namesGenerator->SetOutputDirectory( outputDirectory );<br><br> seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() ); <br>
<br></font><font face="courier new,monospace"> <b>// BEGIN IMPORTANT CODE</b></font><font face="courier new,monospace"><br> <b>seriesWriter->SetMetaDataDictionaryArray( &outputArray );</b> <br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // instead of </span></font><font style="font-family: courier new,monospace;" face="courier new,monospace">:</font><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // seriesWriter->SetMetaDataDictionaryArray( reader->GetMetaDataDictionaryArray() );</span><br style="font-family: courier new,monospace;">
<font face="courier new,monospace"><b style="font-family: courier new,monospace;"> // END</b><br><br> seriesWriter->Update(); </font><br><br><br><br><br><br>Thank you again Martin ;-)<br><br><br><br><br>Stéphane<br><br>
<br><br><br><br><br><div class="gmail_quote">2008/11/19 Martin Kavec <span dir="ltr"><<a href="mailto:martin.kavec@gmail.com">martin.kavec@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Stephane,<br>
<br>
I was on the same issue two days ago with the same results. The problem is<br>
that each slice in your input series has unique MetaDataDictionary, so you<br>
have to change the field you desire in all of them.<br>
<br>
I have found in the ITK mailing list archives a post from Bill (I guess) where<br>
he send attached a file DicomResample which does what you need. Just google<br>
for DicomResample and the very first reference is what you need.<br>
<br>
Regards,<br>
<font color="#888888"><br>
Martin<br>
</font><div><div></div><div class="Wj3C7c"><br>
On Wednesday 19 November 2008 13:38:06 Stéphane CALANDE wrote:<br>
> Oh sorry, there was a mistake in the entry...<br>
><br>
> But the field is still not modified... :-(<br>
><br>
><br>
> Any other idea ?<br>
><br>
><br>
> Thank you Bill ;-)<br>
><br>
><br>
><br>
><br>
> Stéphane<br>
><br>
><br>
><br>
><br>
> 2008/11/19 Bill Lorensen <<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>><br>
><br>
> > Try<br>
> > std::string entryId("0008|103e");<br>
> > instead of<br>
> > std::string entryId("008|103e");<br>
> ><br>
> > Bill<br>
> ><br>
> > On Wed, Nov 19, 2008 at 6:53 AM, Stéphane CALANDE <<a href="mailto:scalande@gmail.com">scalande@gmail.com</a>><br>
> ><br>
> > wrote:<br>
> > > Hi itk-list,<br>
> > ><br>
> > ><br>
> > > I'm using the example of "DicomSeriesReadSeriesWrite", but I'd like to<br>
> > > modify one DICOM header field before writing the Series.<br>
> > ><br>
> > > Then I had a look in "DicomImageReadChangeHeaderWrite" and I tried to<br>
> ><br>
> > apply<br>
> ><br>
> > > the part of the code that change the header field into the code of<br>
> > > "DicomSeriesReadSeriesWrite".<br>
> > ><br>
> > ><br>
> > > But it doesn't seem to work. The field I want to change has not changed<br>
> ><br>
> > in<br>
> ><br>
> > > the output files. Could you have a look in the (simplified) following<br>
> ><br>
> > code<br>
> ><br>
> > > to help me ?<br>
> > ><br>
> > ><br>
> > ><br>
> > > typedef signed short PixelType;<br>
> > > const unsigned int Dimension = 3;<br>
> > > typedef itk::Image< PixelType, Dimension > ImageType;<br>
> > > typedef itk::ImageSeriesReader< ImageType > ReaderType;<br>
> > > typedef itk::ImageFileReader< ImageType > ReaderMHDType;<br>
> > > typedef itk::GDCMImageIO ImageIOType;<br>
> > > typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br>
> > ><br>
> > > ImageIOType::Pointer gdcmIO = ImageIOType::New();<br>
> > > NamesGeneratorType::Pointer namesGenerator =<br>
> > > NamesGeneratorType::New();<br>
> > ><br>
> > > namesGenerator->SetInputDirectory( [...DIRECTORY...] );<br>
> > ><br>
> > > const ReaderType::FileNamesContainer & filenames =<br>
> > > namesGenerator->GetInputFileNames();<br>
> > ><br>
> > > ReaderType::Pointer reader = ReaderType::New();<br>
> > ><br>
> > > reader->SetImageIO( gdcmIO );<br>
> > > reader->SetFileNames( filenames );<br>
> > ><br>
> > > reader->Update();<br>
> > ><br>
> > > // BEGIN => I'm trying to modify one DICOM Header field <<<<br>
> > ><br>
> > > typedef itk::MetaDataDictionary DictionaryType;<br>
> > ><br>
> > > ImageType::Pointer inputImage = reader->GetOutput();<br>
> > > DictionaryType & dictionary = inputImage->GetMetaDataDictionary();<br>
> > ><br>
> > > std::string entryId("008|103e");<br>
> > > std::string value("NEW VALUE");<br>
> > ><br>
> > > itk::EncapsulateMetaData<std::string>( dictionary, entryId, value );<br>
> > ><br>
> > > // END<br>
> > ><br>
> > > [...]<br>
> > ><br>
> > > typedef signed short OutputPixelType;<br>
> > > const unsigned int OutputDimension = 2;<br>
> > ><br>
> > > typedef itk::Image< OutputPixelType, OutputDimension ><br>
> > > Image2DType;<br>
> > ><br>
> > > typedef itk::ImageSeriesWriter< ImageType, Image2DType ><br>
> > > SeriesWriterType;<br>
> > ><br>
> > > SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();<br>
> > ><br>
> > > seriesWriter->SetInput( [...VOLUME...] );<br>
> > > seriesWriter->SetImageIO( gdcmIO );<br>
> > ><br>
> > > namesGenerator->SetOutputDirectory( outputDirectory );<br>
> > ><br>
> > > seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );<br>
> > ><br>
> > > seriesWriter->SetMetaDataDictionaryArray(<br>
> > > reader->GetMetaDataDictionaryArray() );<br>
> > ><br>
> > > seriesWriter->Update();<br>
> > ><br>
> > ><br>
> > ><br>
> > ><br>
> > > I would be very grateful if you could help me.<br>
> > ><br>
> > ><br>
> > > Thank you very much,<br>
> > ><br>
> > ><br>
> > ><br>
> > > Stéphane<br>
> > ><br>
> > > _______________________________________________<br>
> > > Insight-users mailing list<br>
> > > <a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><br>
> > > <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br>