<div>Hi Mathieu,</div>
<div> </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 I had a series of 2D dicom files, then I used volview and paraview 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> </div>
<div> </div>
<div> </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 "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkRescaleIntensityImageFilter.h"<br>#include "itkGDCMImageIO.h"<br>#include "itkGDCMSeriesFileNames.h
"<br>#include "itkImageSeriesWriter.h"<br>#include "itkImageSeriesReader.h"</p>
<p>#include <list><br>#include <fstream></p>
<p>int main( int argc, char* argv[] ) {</p>
<p> // Verify the number of parameters in the command line<br> if( argc < 4 ) {<br> std::cerr << "Usage: " << std::endl;<br> std::cerr << argv[0] << " vtkImage InputDicomImage ";
<br> std::cerr << " OutputImage \n";<br> return EXIT_FAILURE;<br> }</p>
<p> typedef signed short InputPixelType;<br> //typedef float InputPixelType;<br> const unsigned int InputDimension = 3;</p>
<p> typedef itk::Image< InputPixelType, InputDimension > ImageType;<br> <br> typedef itk::ImageSeriesReader< ImageType > ReaderType;<br> <br> typedef itk::ImageFileReader< ImageType > ReaderType2;<br>
ReaderType2::Pointer reader2 = ReaderType2::New();<br> reader2->SetFileName( argv[1] );</p>
<p> <br> typedef itk::GDCMImageIO ImageIOType;<br> ImageIOType::Pointer gdcmIO = ImageIOType::New();<br> <br> typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br> NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
</p>
<p><br> namesGenerator->SetInputDirectory( argv[2] );<br> const ReaderType::FileNamesContainer & filenames = <br> namesGenerator->GetInputFileNames();</p>
<p> unsigned int numberOfFilenames = filenames.size();<br> std::cout << numberOfFilenames << std::endl; <br> for(unsigned int fni = 0; fni<numberOfFilenames; fni++)<br> {<br> std::cout << "filename # " << fni << " = ";
<br> std::cout << filenames[fni] << std::endl;<br> }<br> <br> ReaderType::Pointer reader = ReaderType::New();<br> reader->SetImageIO( gdcmIO );<br> reader->SetFileNames( filenames );</p>
<p> try {<br> reader->Update();<br> }<br> catch (itk::ExceptionObject & e) {<br> std::cerr << "exception in file reader " << std::endl;<br> std::cerr << e << std::endl;<br> return EXIT_FAILURE;
<br> }</p>
<p> const char * outputDirectory = argv[3];<br> itksys::SystemTools::MakeDirectory( outputDirectory );</p>
<p> typedef signed short OutputPixelType;<br> //typedef float OutputPixelType;<br> const unsigned int OutputDimension = 2;</p>
<p> typedef itk::Image< OutputPixelType, OutputDimension > Image2DType;<br> typedef itk::ImageSeriesWriter< ImageType, Image2DType > SeriesWriterType;</p>
<p> SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();<br> seriesWriter->SetInput( reader2->GetOutput() );<br> seriesWriter->SetImageIO( gdcmIO );</p>
<p> namesGenerator->SetOutputDirectory( outputDirectory );<br> seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );</p>
<p> seriesWriter->SetMetaDataDictionaryArray( <br> reader->GetMetaDataDictionaryArray() );</p>
<p><br> try {<br> seriesWriter->Update();<br> }<br> catch( itk::ExceptionObject & excp ) {<br> std::cerr << "Exception thrown while writing the series " << std::endl;<br> std::cerr << excp << std::endl;
<br> return EXIT_FAILURE;<br> }</p>
<p><br> return 0;</p>
<p><br>}</p><br><br> </div>
<div><span class="gmail_quote">On 6/6/06, <b class="gmail_sendername">Mathieu Malaterre</b> <<a href="mailto:mathieu.malaterre@kitware.com">mathieu.malaterre@kitware.com</a>> 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>> Hi,<br>><br>> Does anybody know whether a 3D vtk file can be converted into a series
<br>> 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>