[Insight-users] converting a pointset to an image and then converting the image to DICOM volume

Zien superz9 at gmail.com
Tue Oct 18 12:15:41 EDT 2005


Hi,all:

Could anyone tell me what is the problem I have when converting a pointset
to an image and then converting the image to DICOM volume with the
PointSetToImage and ImageFileWriter class?

Kind Regards!

My code as follows:

int main(int argc, char * argv[] )
{

  if( argc < 3 )
    {
    std::cerr << "Arguments Missing. " << std::endl;
    std::cerr << "Usage:  PointToDicom  PointSetFileName 
OutputDicomFileName " << std::endl;
    return 1;
    }

  const unsigned int Dimension = 3;

  typedef itk::PointSet< float, Dimension >   PointSetType;
  PointSetType::Pointer PointSet1  = PointSetType::New();


  typedef PointSetType::PointsContainer  PointsContainer;	
  PointsContainer::Pointer PointContainer1  = PointsContainer::New();


  typedef PointSetType::PointType     PointType;
  PointType Point1; 					

  std::ifstream   file1;
  file1.open( argv[1] );

  if( file1.fail() )	
    {
    std::cerr << "Error opening points file with name : " << std::endl;
    std::cerr << argv[1] << std::endl;
    return 2;
    }

  unsigned int pointId = 0;
  file1 >> Point1;
  while( !file1.eof() )
    {
    PointContainer1->InsertElement( pointId, Point1 );
    file1 >> Point1;
    pointId++;
    }
  PointSet1->SetPoints( PointContainer1 );




  typedef itk::Image< unsigned char,  Dimension >  BinaryImageType;


  typedef itk::PointSetToImageFilter<PointSetType,BinaryImageType>
PointsToImageFilterType;

  PointsToImageFilterType::Pointer  pointsToImageFilter =
PointsToImageFilterType::New();


  pointsToImageFilter->SetInput( PointSet1 );

  BinaryImageType::SpacingType spacing;
  spacing.Fill( 1.0 );

  BinaryImageType::PointType origin;
  origin.Fill( 0.0 );

  pointsToImageFilter->SetSpacing( spacing );
  pointsToImageFilter->SetOrigin( origin   );

  pointsToImageFilter->Update();


  typedef itk::ImageFileWriter< BinaryImageType >  WriterType;
  WriterType::Pointer writer1 = WriterType::New();


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

  writer1->SetImageIO( dicomIO );
  writer1->SetFileName( argv[2] );
  writer1->SetInput( pointsToImageFilter->GetOutput() );


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

  return EXIT_SUCCESS;
}


More information about the Insight-users mailing list