[ITK] Dicom reading and writing issues

Eriksson, Mikael mikael.k.eriksson at philips.com
Mon Jun 9 03:52:47 EDT 2014


Hi again,

Just rudely bumping my original message here (see below). I re-read it, and I hope it is clear enough, but if not, do not hesitate to ask for clarifications. I still haven't got this issue resolved unfortunately.

Best,
Mikael


======================================================================================================================================================

Hi all,

I'm learning ITK, and am currently in the process of setting up a testing program for an image registration algorithm. I will have to read and write dicoms quite a few times within the program execution, so instead of doing all the steps of the read/write processes every time, I decided to write separate functions for them. Since I have to use some data from the reading process, such as the MetaDataDictionaryArray in the output as well, the readDicom-function (as well as another function, preregistrationOperations) returns a  tuple:

typedef std::tuple< ImageType::Pointer, MetaDataContainer, FileNamesContainer > ImageMetaOutputTuple;


The other types are the same as in the ITK-examples for Dicom-handling. The rough layout of my program is seen below.

This program crashes in the writeDicom-function however, with the error "...vector subscript out of range". I have narrowed the error down to having to do with the MetaDataDictionaryArray. Its size when the dicoms are first read in reaDicom is e.g. 64 (the number of files in the series), but when it is returned to the preRegistrationOperations, its size is suddenly 0, and it is this zero-sized container that is then passed to writeDicom which crashes.

I have tried to get around this problem by using MetaDataContainer-pointers instead, but the problem persists. I might add that I'm quite new to C++ too (more of a physicist than a programmer). Can anybody help me in this? It should be simple enough to return a MetaDataContainer within a tuple from readDicom, unpack it in preRegistrationOperations, and pass it to writeDicom, but no matter how I try I can't get it to work.

Best regards,
Mikael


ImageMetaOutputTuple preRegistrationOperations( std::string inputDir,  std::string outputDir, std::string seriesNumber, bool preparationsDone = false, bool verbose = true )
{
       // No output verbose if operations have already been done
       if (preparationsDone) verbose = false;

       // Read input-Dicoms
       ImageType::Pointer image;
       MetaDataContainer metaData;
       FileNamesContainer outputFilenames;
       ImageMetaOutputTuple returnTuple = readDicom( inputDir, outputDir, seriesNumber, verbose );
       std::tie (image, metaData, outputFilenames) = returnTuple;

       // Pass image and directory and filename information to writeDicom and write into outputDir
       if (!preparationsDone) {
              try {
                     int resultCode = writeDicom( image, outputDir, outputFilenames, metaData );
              }
              catch (itk::ExceptionObject &ex) {
                     std::cout << "Exception caught in writeDICOM:" << std::endl;
                     std::cout << ex << std::endl;
              }
       }
       return returnTuple;
}


int writeDicom ( ImageType::Pointer image, std::string inputDir, FileNamesContainer filenames, MetaDataContainer metaData )
{
                ...
                seriesWriter->SetMetaDataDictionaryArray( metaData );
       ...
}


ImageMetaOutputTuple readDicom ( std::string inputDir, std::string outputDir = "", std::string seriesNumber = "", bool verbose = true)
{
       ...
       image = reader->GetOutput();
       files = nameGenerator->GetOutputFileNames();
       MetaDataContainer metaData = reader->GetMetaDataDictionaryArray();
              ...
ImageMetaOutputTuple returnTuple (image, metaData, files);
return returnTuple;
}


int main( int argc, char* argv[] )
{
       ...
       ImageType::Pointer moving;
       ImageType::Pointer target;
       std::tie(moving, std::ignore, std::ignore) = preRegistrationOperations( inputDir, movingDir, movingSeriesNumber, preparationsDone, verbose );
       std::tie(target, std::ignore, std::ignore) = preRegistrationOperations( inputDir, targetDir, targetSeriesNumber, preparationsDone, verbose );
       ...
}


.......................................................................................................
Mikael Eriksson
R&D Physicist Trainee
Philips Medical Systems MR Finland, Feasibility studies

+358 40 631 8500
mikael.k.eriksson at philips.com<mailto:mikael.k.eriksson at philips.com>
.......................................................................................................


________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140609/f43b6ed7/attachment-0002.html>


More information about the Community mailing list