[Insight-users] Re : Output dicom series in new directory

Ezequiel Geremia t-egerem at microsoft.com
Tue Jun 23 19:26:40 EDT 2009


Hi Syrine,

Thank you for your help

I managed to solve the problem by using NumericSeriesFileNames class.

However some issues remain unsolved due to incompatibility between windows and unix path separators, that forces the executable to be used in the same file as the the header.

Attached the resulting code

Many thanks,

Ezequiel

From: Syrine Sahmim [mailto:syrine.sahmim at yahoo.fr]
Sent: 23 June 2009 18:55
To: Ezequiel Geremia
Cc: insight-users at itk.org
Subject: Re : [Insight-users] Output dicom series in new directory

this is my code and you must verify your cmake file
#include "itkImageSeriesReader.h"
#include "itkDICOMImageIO2.h"
#include "itkDICOMSeriesFileNames.h"
#include "itkImageFileWriter.h"

int main( int argc, char* argv[] )
{
/*
  if( argc < 3 )
    {
    std::cerr << "Usage: " << argv[0] << " DicomDirectory  outputFileName  [seriesName]" << std::endl;
    return EXIT_FAILURE;
    }
*/

    argc = 2;
    argv[1] = "dicom";
    argv[2] = "dicomMRA.hdr";

  typedef itk::Image<short,3>            ImageType;
  typedef itk::ImageSeriesReader< ImageType >     ReaderType;

  itk::DICOMImageIO2::Pointer dicomIO = itk::DICOMImageIO2::New();

  // Get the DICOM filenames from the directory
  itk::DICOMSeriesFileNames::Pointer nameGenerator = itk::DICOMSeriesFileNames::New();
  nameGenerator->SetDirectory( argv[1] );


  try
    {
    typedef std::vector<std::string> seriesIdContainer;
    const seriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();

    seriesIdContainer::const_iterator seriesItr = seriesUID.begin();
    seriesIdContainer::const_iterator seriesEnd = seriesUID.end();

    std::cout << std::endl << "The directory: " << std::endl;
    std::cout << std::endl << argv[1] << std::endl << std::endl;
    std::cout << "Contains the following DICOM Series: ";
    std::cout << std::endl << std::endl;

    while( seriesItr != seriesEnd )
      {
      std::cout << seriesItr->c_str() << std::endl;
      seriesItr++;
      }

    std::cout << std::endl << std::endl;
    std::cout << "Now reading series: " << std::endl << std::endl;

    typedef std::vector<std::string> fileNamesContainer;
    fileNamesContainer fileNames;

    if( argc < 4 ) // If no optional third argument
      {
      std::cout << seriesUID.begin()->c_str() << std::endl;
      fileNames = nameGenerator->GetFileNames();
      }
    else
      {
      std::cout << argv[3] << std::endl;
      fileNames = nameGenerator->GetFileNames( argv[3] );
      }
    std::cout << std::endl << std::endl;

    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileNames( fileNames );
    reader->SetImageIO( dicomIO );

    try
      {
      reader->Update();
      }
    catch (itk::ExceptionObject &ex)
      {
      std::cout << ex << std::endl;
      return EXIT_FAILURE;
      }

    typedef itk::ImageFileWriter< ImageType > WriterType;
    WriterType::Pointer writer = WriterType::New();

    std::cout  << "Writing the image as " << std::endl << std::endl;
    std::cout  << argv[2] << std::endl << std::endl;

    writer->SetFileName( argv[2] );

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

    try
      {
      writer->Update();
      }
    catch (itk::ExceptionObject &ex)
      {
      std::cout << ex;
      return EXIT_FAILURE;
      }
    }
  catch (itk::ExceptionObject &ex)
    {
    std::cout << ex;
    return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;

}

i hope that will help you. tell wether your program goes on or not




________________________________
De : Ezequiel Geremia <t-egerem at microsoft.com>
À : Mathieu Malaterre <mathieu.malaterre at gmail.com>
Cc : "insight-users at itk.org" <insight-users at itk.org>
Envoyé le : Mardi, 23 Juin 2009, 16h18mn 52s
Objet : Re: [Insight-users] Output dicom series in new directory

No exception is thrown. The output dicom series are not created in the requested Directory.

Moreover Syrine, there is not a matter of reading nrrd format, it is just a matter of outputting generated files in the right directory.

If already have had that problem and resolve it you can send me the file so that I can compare it with mine. It will help me solving that issue.

Thanks,

Ezequiel

-----Original Message-----
From: Mathieu Malaterre [mailto:mathieu.malaterre at gmail.com<mailto:mathieu.malaterre at gmail.com>]
Sent: 23 June 2009 16:11
To: Ezequiel Geremia
Cc: insight-users at itk.org<mailto:insight-users at itk.org>
Subject: Re: [Insight-users] Output dicom series in new directory

On Tue, Jun 23, 2009 at 4:45 PM, Ezequiel Geremia<t-egerem at microsoft.com<mailto:t-egerem at microsoft.com>> wrote:
> Hi insight-users,
>
> I wrote a code inspired from itkSoftwraeGuide to convert nrrd files into dicom series.
>
> When running the executable on windows vista, the latter does not output the dicom slices in the directory specified through
>
> typedef itk::GDCMSeriesFileNames NamesGeneratorType;
> NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
>
> namesGenerator->SetOutputDirectory( outputDirectory );
>
> Do you have an idea on how to resolve that issue ?

I have absolutely no idea. But if you send the output of the
executable, I might help. just print the exception that's thrown
during the call to Update() (or Write()) and send it to the list.

2cts

--
Mathieu

_____________________________________
Powered by www.kitware.com<http://www.kitware.com>

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

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://www.itk.org/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090624/cdeef872/attachment-0001.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ConvertIntoDicomSeries.cpp
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090624/cdeef872/attachment-0001.txt>


More information about the Insight-users mailing list