[Insight-users] DiffusionTensor3DReconstructionImageFilter (cont.)

Christina Roßmanith ChrRossmanith at gmx.de
Fri Oct 20 16:05:26 EDT 2006


Hi,

attaching the source code didn't work, following you find my source code
pasted.

Christina Rossmanith

----------------------------------------------------------------------------------------------------------------------------------------------
#include <itkImageSeriesReader.h>
#include "itkGDCMSeriesFileNames.h"
#include <itkGDCMImageIO.h>
#include "itkImageFileWriter.h"
#include <itkDiffusionTensor3DReconstructionImageFilter.h>
#include "itkImageFileWriter.h"


int main ( int argc, char* argv[] )
{
  typedef signed short                          PixelType;
  const unsigned int                            Dimension = 3;
  typedef itk::Image< PixelType, Dimension >    ImageType;

  typedef itk::ImageSeriesReader< ImageType >   ReaderType;
  ReaderType::Pointer reader = ReaderType::New();

  typedef itk::GDCMImageIO                      ImageIOType;
  ImageIOType::Pointer dicomIO = ImageIOType::New();

  reader->SetImageIO( dicomIO );

  typedef itk::GDCMSeriesFileNames              NamesGeneratorType;
  NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
  nameGenerator->SetUseSeriesDetails( true );
  if (argc > 1)
    {
    nameGenerator->SetDirectory( argv[1] );
    }
  else
    {
    nameGenerator->SetDirectory( "/tmp/Singer" );
    }


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


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


  typedef itk::DiffusionTensor3DReconstructionImageFilter<
    PixelType, PixelType, double > TensorReconstructionImageFilterType;
  TensorReconstructionImageFilterType::GradientDirectionType    vect3d;

TensorReconstructionImageFilterType::GradientDirectionContainerType::Pointer 


    diffusionVectors =
TensorReconstructionImageFilterType::GradientDirectionContainerType::New();
  TensorReconstructionImageFilterType::Pointer tensorReconstructor =
TensorReconstructionImageFilterType::New();

  //
  // read gradient directions from file
  //
  std::ifstream   gradientFile;

  gradientFile.open ( argv[2] );

  std::string     line;
  unsigned int    count=0;


  if (gradientFile.is_open())
    {
    while (! gradientFile.eof())
      {
      getline (gradientFile, line);
      std::istringstream (line) >> vect3d[0] >> vect3d[1] >> vect3d[2];
      diffusionVectors->InsertElement (count, vect3d);
      count++;
      }
    }



  //
  // read 7 series (1 reference + 6 diffusion weighted)
  //
  count = 0;
  while( seriesItr != seriesEnd )
    {
    std::string seriesIdentifier;
    seriesIdentifier = seriesItr->c_str();

    typedef std::vector< std::string >            FilenamesContainer;
    FilenamesContainer filenames;

    // read a single serie
    filenames = nameGenerator->GetFileNames( seriesIdentifier );
    reader->SetFileNames( filenames );
    reader->Update();


    // first serie is reference
    if (count == 0)
      {
      tensorReconstructor->SetReferenceImage (reader->GetOutput());
      }
    // series 2-7 are diffusion weighted
    else
      {
      vect3d = diffusionVectors->GetElement( count );
      vect3d.normalize();
      tensorReconstructor->AddGradientImage (vect3d, reader->GetOutput());
      }
    count ++;
    seriesItr++;
    }

  // parameterize tensor reconstruction filter
  tensorReconstructor->SetNumberOfThreads( 1 );
  tensorReconstructor->SetBValue( 1000.0 );
  tensorReconstructor->SetThreshold ( 0 );


  tensorReconstructor->Update();


  // write resulting tensor volume
  typedef itk::ImageFileWriter<
TensorReconstructionImageFilterType::TensorImageType > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName( argv[3] );
  writer->SetInput( tensorReconstructor->GetOutput() );
  writer->Update();

  exit (EXIT_SUCCESS);
}




More information about the Insight-users mailing list