[Insight-users] vtk to dicom converstion
Ming Chao
mingchao2005 at gmail.com
Wed Jun 7 14:08:27 EDT 2006
Hi Mathieu,
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.
Thanks,
Ming
// ----------------------------------------------------------------------
//
// a program used to convert 3D vtk file to a series of 2D dicom files
//
//
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkImageSeriesWriter.h"
#include "itkImageSeriesReader.h"
#include <list>
#include <fstream>
int main( int argc, char* argv[] ) {
// Verify the number of parameters in the command line
if( argc < 4 ) {
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " vtkImage InputDicomImage ";
std::cerr << " OutputImage \n";
return EXIT_FAILURE;
}
typedef signed short InputPixelType;
//typedef float InputPixelType;
const unsigned int InputDimension = 3;
typedef itk::Image< InputPixelType, InputDimension > ImageType;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
typedef itk::ImageFileReader< ImageType > ReaderType2;
ReaderType2::Pointer reader2 = ReaderType2::New();
reader2->SetFileName( argv[1] );
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer gdcmIO = ImageIOType::New();
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
namesGenerator->SetInputDirectory( argv[2] );
const ReaderType::FileNamesContainer & filenames =
namesGenerator->GetInputFileNames();
unsigned int numberOfFilenames = filenames.size();
std::cout << numberOfFilenames << std::endl;
for(unsigned int fni = 0; fni<numberOfFilenames; fni++)
{
std::cout << "filename # " << fni << " = ";
std::cout << filenames[fni] << std::endl;
}
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO( gdcmIO );
reader->SetFileNames( filenames );
try {
reader->Update();
}
catch (itk::ExceptionObject & e) {
std::cerr << "exception in file reader " << std::endl;
std::cerr << e << std::endl;
return EXIT_FAILURE;
}
const char * outputDirectory = argv[3];
itksys::SystemTools::MakeDirectory( outputDirectory );
typedef signed short OutputPixelType;
//typedef float 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( reader2->GetOutput() );
seriesWriter->SetImageIO( gdcmIO );
namesGenerator->SetOutputDirectory( outputDirectory );
seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );
seriesWriter->SetMetaDataDictionaryArray(
reader->GetMetaDataDictionaryArray() );
try {
seriesWriter->Update();
}
catch( itk::ExceptionObject & excp ) {
std::cerr << "Exception thrown while writing the series " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return 0;
}
On 6/6/06, Mathieu Malaterre <mathieu.malaterre at kitware.com> wrote:
>
> Ming Chao wrote:
> > Hi,
> >
> > Does anybody know whether a 3D vtk file can be converted into a series
> > of 2D dicom images in ITK? Thanks.
Yes and no :)
> Yes, you can read a 3D vtk image file, and yes you can write an
> itk::Image into a series of DICOM files.
>
> No, because by default GDCM is writing Secondary Image Capture which
> does not have the Patient Module and therefore cannot be reconstructed
> as a volume (no Image Position/Orientation (Patient)) if you use any
> serious DICOM reader.
> So you'll need an additional step in defining what is your DICOM Object
> (MR, CT, RT...)
>
> 2 cents
> Mathieu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060607/887ed5bf/attachment.htm
More information about the Insight-users
mailing list