[Insight-users] read-reslice-write 3D DICOM dataset

Matthias Schabel mschabel at ucair.med.utah.edu
Thu Mar 5 14:54:41 EST 2009


I am trying to do something seemingly simple : read in a 3D DICOM  
volume acquired in coronal orientation, reslice in the sagittal plane,  
and write the resulting resliced data, with updated DICOM headers out,  
but am running into problems... There are two problems using the code  
pasted below : 1) I get something that looks like sagitally  
reformatted data if I write the whole data set as a single 3D DICOM  
object, but the metadata is not preserved and the slice locations look  
screwy, 2) If I try to output a set of 2D images (uncommenting the  
appropriate lines below), I get a strange error :

exception in ImageSeriesWriter

itk::ExceptionObject (0xeaf480)
Location: "void itk::ImageSeriesWriter<TInputImage,  
TOutputImage>::GenerateData() [with TInputImage = main(int, char*  
const*)::OutputType, TOutputImage = main(int, char*  
const*)::OutputType]"
File: /usr/local/include/itk/IO/itkImageSeriesWriter.txx
Line: 315
Description: itk::ERROR: ImageSeriesWriter(0xea7010): The number of  
filenames passed is 256 but 1 were expected

Does anyone have a simple functioning driver program that does this  
sort of reslicing/output of DICOM data or any suggestions on where I'm  
going wrong?

Thanks,

Matthias


                         // set up ITK DICOM image series reader
                         typedef itk::OrientedImage<short,3>	InputType;
                         typedef itk::OrientedImage<short,3>	OutputType;

                         itk::ImageSeriesReader<InputType>::Pointer   
reader = itk::ImageSeriesReader<InputType>::New();

                         std::cout << "Loading files for time point "  
<< frameIndex << " : "
                                   << currentFrameFilenameList.front()  
<< " - " << currentFrameFilenameList.back()
                                   << "...";

                         reader->SetFileNames(currentFrameFilenameList);

                         try
                         {
                             reader->Update();
                         }
                         catch (itk::ExceptionObject& e)
                         {
                             std::cerr << "exception in  
ImageSeriesReader " << std::endl;
                             std::cerr << e << std::endl;

                             //throw;
                             return -1;
                         }

                         std::cout << "Read size : " << reader- 
 >GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl;

                         // get DICOM metadata
                         const std::vector<itk::MetaDataDictionary*>&	 
current_dict_array = *(reader->GetMetaDataDictionaryArray());

                         const itk::MetaDataDictionary&    dict =  
*(current_dict_array.back());

                         std::cout << "loaded " <<  
currentFrameFilenameList.size() << " files in " << bench.seconds() <<  
" seconds" << std::endl;

                         // reslice data
                          
itk::OrientImageFilter<InputType,OutputType>::Pointer   orienter =  
itk::OrientImageFilter<InputType,OutputType>::New();

                         orienter->UseImageDirectionOn();
                         orienter- 
 > 
SetDesiredCoordinateOrientation 
(itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_PSL); // sagittal  
orientation
                         orienter->SetInput(reader->GetOutput());

                         try
                         {
                             orienter->Update();
                         }
                         catch (itk::ExceptionObject& e)
                         {
                             std::cerr << "exception in  
OrientImageFilter " << std::endl;
                             std::cerr << e << std::endl;

                             //throw;
                             return -1;
                         }

                         std::cout << "Oriented size : " << orienter- 
 >GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl;

                         typedef itk::OrientedImage<short,2>  
OutputType2D;

//                         
itk::ImageSeriesWriter<OutputType,OutputType2D>::Pointer  writer =  
itk::ImageSeriesWriter<OutputType,OutputType2D>::New();
                          
itk::ImageSeriesWriter<OutputType,OutputType>::Pointer  writer =  
itk::ImageSeriesWriter<OutputType,OutputType>::New();

                         writer->SetInput(orienter->GetOutput());

                         typedef itk::GDCMImageIO    ImageIOType;

                         ImageIOType::Pointer    gdcmImageIO =  
ImageIOType::New();

                         gdcmImageIO->KeepOriginalUIDOn();

                         writer->SetImageIO(gdcmImageIO);
                         writer->SetMetaDataDictionary(dict);
//                        writer- 
 >SetMetaDataDictionaryArray(current_dict_array);

                         // generate output filenames
                         std::vector<std::string>	outputFilenames;

                         outputFilenames.push_back("/Users/ 
matthiasschabel/Temporary/IMTEST.dcm");

//                        const OutputType::SizeType  sz = orienter- 
 >GetOutput()->GetLargestPossibleRegion().GetSize();
//
//                        for (int sliceIndex=0;sliceIndex<sz[2];+ 
+sliceIndex)
//                        {
//                            std::stringstream   sstr;
//
//                            sstr << "/Users/matthiasschabel/ 
Temporary/IMTEST-"
//                                 << std::setw(4) <<  
std::setfill('0') << frameIndex
//                                 << "-"
//                                 << std::setw(4) <<  
std::setfill('0') << sliceIndex
//                                 << ".dcm";
//
//                            outputFilenames.push_back(sstr.str());
//
//                            std::cout << sstr.str() << std::endl;
//                        }
	
                         writer->SetFileNames(outputFilenames);

                         try
                         {
                             writer->Update();
                         }
                         catch (itk::ExceptionObject& e)
                         {
                             std::cerr << "exception in  
ImageSeriesWriter " << std::endl;
                             std::cerr << e << std::endl;

                             //throw dicom::Exception();
                             return -1;
                         }
                     }

                     std::cout << "Processing for study "
                               << lastName << "," << firstName << " "  
<< dateString
                               << " successfully completed..."
                               << std::endl << std::endl;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090305/95c948e1/attachment-0001.htm>


More information about the Insight-users mailing list