[ITK] [ITK-users] itk - Writing dicom files from single 3D file

AI audrey.istace at imavie.fr
Mon Mar 23 11:11:13 EDT 2015


Hello,

I would like to write Dicom files from a nifti image files using
DCMTKImageIO. In the code below, I read a nifti file using
itkImageFileReader, and then try to write dicom files using
itkImageSeriesWriter. I was not able to do it, probably because of the
SetMetaDataDictionaryArray method, that I don’t know how to use since I
don’t read dicom series as input. Can you help me with that ?

Thank you very much,

Audrey

#include "itkDCMTKImageIO.h"
#include "itkNumericSeriesFileNames.h"
#include "itkImageFileReader.h"
#include "itkImageSeriesWriter.h"

int main(int argc, char *argv[])
{
               typedef signed short                                            
PixelType;
               const unsigned int                                              
Dimension = 3;
               typedef itk::Image< PixelType, Dimension >                      
ImageType;
               typedef itk::Image< PixelType, 2 >                              
OutputImageType;
               typedef itk::ImageFileReader< ImageType >                       
ReaderType;
               typedef itk::DCMTKImageIO                                       
ImageIOType;
               typedef itk::NumericSeriesFileNames                             
NamesGeneratorType;
               typedef itk::ImageSeriesWriter< ImageType, OutputImageType >    
WriterType;
               
               ImageIOType::Pointer dcmtkIO = ImageIOType::New();
               NamesGeneratorType::Pointer namesGenerator =
NamesGeneratorType::New();
               ReaderType::Pointer reader = ReaderType::New();
               WriterType::Pointer writer = WriterType::New();
               
               reader->SetFileName( "../../out.nii" );
               reader->Update();
               
               
               
               itksys::SystemTools::MakeDirectory( "../../OutputDicom/" );
               
               std::string seriesFormat = "../../OutputDicom/IM%d.dcm";
               namesGenerator->SetSeriesFormat (seriesFormat.c_str());
               namesGenerator->SetStartIndex (1);
               namesGenerator->SetEndIndex (166);
               
               
               writer->SetInput( reader->GetOutput() );
               writer->SetImageIO( dcmtkIO );
               writer->SetFileNames( namesGenerator->GetFileNames() );
//           writer->SetMetaDataDictionaryArray(
reader->GetMetaDataDictionaryArray() );
               writer->Update();
}




--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/itk-Writing-dicom-files-from-single-3D-file-tp7587034.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list