If someone is interrested, here is the code of a program that takes as input :<br><br>&gt; a repertory of a DICOM series<br>&gt; a volume .MHD having the same resolution, spacing, origin, number of slices,... than the series (containing )<br>
&gt; an output directory<br><br>an that gives, as output, a DICOM Series with the headers of the first DICOM series but with the pixels of the volume MHD<br><br>(It&#39;s a modification of the code &quot;Examples/IO/DicomSeriesReadSeriesWrite.cxx&quot;)<br>
<br>++<br><br>Stéphane<br><br><br><span style="font-family: courier new,monospace;">#if defined(_MSC_VER)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#pragma warning ( disable : 4786 )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#ifdef __BORLANDC__</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#define ITK_LEAN_AND_MEAN</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &quot;itkGDCMImageIO.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &quot;itkGDCMSeriesFileNames.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &quot;itkImageSeriesReader.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &quot;itkImageSeriesWriter.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &lt;vector&gt;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &lt;itksys/SystemTools.hxx&gt;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">int main( int argc, char* argv[] )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; if( argc &lt; 4 )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot; DicomDirectory_having_good_headers MHD_volume_to_convert_to_DICOMseies OutputDicomDirectory&quot; &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; typedef signed short&nbsp;&nbsp;&nbsp; PixelType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; const unsigned int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dimension = 3;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; typedef itk::Image&lt; PixelType, Dimension &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; typedef itk::ImageSeriesReader&lt; ImageType &gt;&nbsp;&nbsp;&nbsp;&nbsp; ReaderType;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; typedef itk::ImageFileReader&lt; ImageType &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReaderMHDType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; typedef itk::GDCMImageIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageIOType;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; typedef itk::GDCMSeriesFileNames&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NamesGeneratorType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; </span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; ImageIOType::Pointer gdcmIO = ImageIOType::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; namesGenerator-&gt;SetInputDirectory( argv[1] );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; const ReaderType::FileNamesContainer &amp; filenames = </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; namesGenerator-&gt;GetInputFileNames();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; unsigned int numberOfFilenames =&nbsp; filenames.size();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; std::cout &lt;&lt; numberOfFilenames &lt;&lt; std::endl; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; for(unsigned int fni = 0; fni&lt;numberOfFilenames; fni++)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;filename # &quot; &lt;&lt; fni &lt;&lt; &quot; = &quot;;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; filenames[fni] &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; ReaderType::Pointer reader = ReaderType::New();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; reader-&gt;SetImageIO( gdcmIO ); // ici on précise qu&#39;on est en train de lire une image au format DICOM</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; reader-&gt;SetFileNames( filenames );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; try</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; reader-&gt;Update();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; catch (itk::ExceptionObject &amp;excp)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Exception thrown while writing the image&quot; &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; excp &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; // à partir d&#39;ici, reader-&gt;getOutput = le volume chargé en mémoire contenant toutes les slices</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; // ici on va loader le volume MHD</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; ReaderMHDType::Pointer readerMHD = ReaderMHDType::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; readerMHD-&gt;SetFileName( argv[2] );</span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; const char * outputDirectory = argv[3];</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; itksys::SystemTools::MakeDirectory( outputDirectory );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; typedef signed short&nbsp;&nbsp;&nbsp; OutputPixelType;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; const unsigned int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputDimension = 2;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; typedef itk::Image&lt; OutputPixelType, OutputDimension &gt;&nbsp;&nbsp;&nbsp; Image2DType;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; typedef itk::ImageSeriesWriter&lt; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageType, Image2DType &gt;&nbsp; SeriesWriterType;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; seriesWriter-&gt;SetInput( readerMHD-&gt;GetOutput() ); // ici on écrit le volume du fichier MHD au lieu de l&#39;original</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; seriesWriter-&gt;SetImageIO( gdcmIO ); // ici on précise qu&#39;on va écrire une image au format DICOM</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; namesGenerator-&gt;SetOutputDirectory( outputDirectory );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; seriesWriter-&gt;SetFileNames( namesGenerator-&gt;GetOutputFileNames() );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; // l&#39;instruction qui suit est très importante, elle copie toutes les infos provenant des headers DICOM (renseignements patients,...)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; // et ici, on prend bien le bon reader (celui de la série DICOM qu&#39;on a chargé au tout début)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; seriesWriter-&gt;SetMetaDataDictionaryArray( </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reader-&gt;GetMetaDataDictionaryArray() );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; try</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; seriesWriter-&gt;Update();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; catch( itk::ExceptionObject &amp; excp )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Exception thrown while writing the series &quot; &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; excp &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; return EXIT_SUCCESS;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br>