<div>Hi Mathieu,</div>
<div>&nbsp;</div>
<div>Thanks for your reply. I could read in a 3D vtk file and write out a series of 2D dicome files with taking the headers from a series of original 2D dicom files. So what I did is the following test. Originally&nbsp;I had a series of 2D dicom files, then I used volview and paraview&nbsp;to form a 3D vtk file. I fed this 3D vtk as the image body data and the header is taken from the original 2D dicom files. I have two questions about this procedure. 1) is this procedure correct? 2) I checked the output 2D dicom files by forming a 3D image using volview but found that AP position was reversed. Don't know why. Hope somebody can have an idea. I attach my code in the following.
</div>
<div>Thanks,</div>
<div>Ming</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>
<p>// ----------------------------------------------------------------------<br>//<br>// a program used to convert 3D vtk file to a series of 2D dicom files<br>//<br>//</p>
<p>#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkImageFileWriter.h&quot;<br>#include &quot;itkRescaleIntensityImageFilter.h&quot;<br>#include &quot;itkGDCMImageIO.h&quot;<br>#include &quot;itkGDCMSeriesFileNames.h
&quot;<br>#include &quot;itkImageSeriesWriter.h&quot;<br>#include &quot;itkImageSeriesReader.h&quot;</p>
<p>#include &lt;list&gt;<br>#include &lt;fstream&gt;</p>
<p>int main( int argc, char* argv[] ) {</p>
<p>&nbsp;// Verify the number of parameters in the command line<br>&nbsp;if( argc &lt; 4 ) {<br>&nbsp;&nbsp;std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;std::cerr &lt;&lt; argv[0] &lt;&lt; &quot; vtkImage InputDicomImage &quot;;
<br>&nbsp;&nbsp;std::cerr &lt;&lt; &quot; OutputImage \n&quot;;<br>&nbsp;&nbsp;return EXIT_FAILURE;<br>&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;typedef signed short InputPixelType;<br>&nbsp;//typedef float InputPixelType;<br>&nbsp;const unsigned int&nbsp;&nbsp; InputDimension = 3;</p>
<p>&nbsp;typedef itk::Image&lt; InputPixelType, InputDimension &gt; ImageType;<br>&nbsp;<br>&nbsp;typedef itk::ImageSeriesReader&lt; ImageType &gt;&nbsp;&nbsp;&nbsp;&nbsp; ReaderType;<br>&nbsp;<br>&nbsp;typedef itk::ImageFileReader&lt; ImageType &gt; ReaderType2;<br>
&nbsp;ReaderType2::Pointer reader2 = ReaderType2::New();<br>&nbsp;reader2-&gt;SetFileName( argv[1] );</p>
<p>&nbsp;<br>&nbsp;typedef itk::GDCMImageIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageIOType;<br>&nbsp;ImageIOType::Pointer gdcmIO = ImageIOType::New();<br>&nbsp;<br>&nbsp;typedef itk::GDCMSeriesFileNames&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NamesGeneratorType;<br>&nbsp;NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
</p>
<p><br>&nbsp;namesGenerator-&gt;SetInputDirectory( argv[2] );<br>&nbsp;const ReaderType::FileNamesContainer &amp; filenames = <br>&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();</p>
<p>&nbsp;unsigned int numberOfFilenames =&nbsp; filenames.size();<br>&nbsp;std::cout &lt;&lt; numberOfFilenames &lt;&lt; std::endl; <br>&nbsp;for(unsigned int fni = 0; fni&lt;numberOfFilenames; fni++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;filename # &quot; &lt;&lt; fni &lt;&lt; &quot; = &quot;;
<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; filenames[fni] &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;<br>&nbsp;ReaderType::Pointer reader = ReaderType::New();<br>&nbsp;reader-&gt;SetImageIO( gdcmIO );<br>&nbsp;reader-&gt;SetFileNames( filenames );</p>
<p>&nbsp;try {<br>&nbsp;&nbsp;reader-&gt;Update();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;catch (itk::ExceptionObject &amp; e) {<br>&nbsp;&nbsp;std::cerr &lt;&lt; &quot;exception in file reader &quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;std::cerr &lt;&lt; e &lt;&lt; std::endl;<br>&nbsp;&nbsp;return EXIT_FAILURE;
<br>&nbsp;}</p>
<p>&nbsp;const char * outputDirectory = argv[3];<br>&nbsp;itksys::SystemTools::MakeDirectory( outputDirectory );</p>
<p>&nbsp;typedef signed short&nbsp;&nbsp;&nbsp; OutputPixelType;<br>&nbsp;//typedef float&nbsp;&nbsp;&nbsp; OutputPixelType;<br>&nbsp;const unsigned int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputDimension = 2;</p>
<p>&nbsp;typedef itk::Image&lt; OutputPixelType, OutputDimension &gt;&nbsp;&nbsp;&nbsp; Image2DType;<br>&nbsp;typedef itk::ImageSeriesWriter&lt; ImageType, Image2DType &gt;&nbsp; SeriesWriterType;</p>
<p>&nbsp;SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();<br>&nbsp;seriesWriter-&gt;SetInput( reader2-&gt;GetOutput() );<br>&nbsp;seriesWriter-&gt;SetImageIO( gdcmIO );</p>
<p>&nbsp;namesGenerator-&gt;SetOutputDirectory( outputDirectory );<br>&nbsp;seriesWriter-&gt;SetFileNames( namesGenerator-&gt;GetOutputFileNames() );</p>
<p>&nbsp;seriesWriter-&gt;SetMetaDataDictionaryArray( <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader-&gt;GetMetaDataDictionaryArray() );</p>
<p><br>&nbsp;try {<br>&nbsp;&nbsp;seriesWriter-&gt;Update();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;catch( itk::ExceptionObject &amp; excp ) {<br>&nbsp;&nbsp;std::cerr &lt;&lt; &quot;Exception thrown while writing the series &quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;std::cerr &lt;&lt; excp &lt;&lt; std::endl;
<br>&nbsp;&nbsp;return EXIT_FAILURE;<br>&nbsp;&nbsp;&nbsp; }</p>
<p><br>&nbsp;return 0;</p>
<p><br>}</p><br><br>&nbsp;</div>
<div><span class="gmail_quote">On 6/6/06, <b class="gmail_sendername">Mathieu Malaterre</b> &lt;<a href="mailto:mathieu.malaterre@kitware.com">mathieu.malaterre@kitware.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Ming Chao wrote:<br>&gt; Hi,<br>&gt;<br>&gt; Does anybody know whether a 3D vtk file can be converted into a series
<br>&gt; of 2D dicom images in ITK? Thanks.</blockquote><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Yes and no :)<br>Yes, you can read a 3D vtk image file, and yes you can write an<br>itk::Image into a series of DICOM files.
<br><br>No, because by default GDCM is writing Secondary Image Capture which<br>does not have the Patient Module and therefore cannot be reconstructed<br>as a volume (no Image Position/Orientation (Patient)) if you use any
<br>serious DICOM reader.<br>So you'll need an additional step in defining what is your DICOM Object<br>(MR, CT, RT...)<br><br>2 cents<br>Mathieu<br></blockquote></div><br>