[Insight-users] read a meta image and write it to DICOM

=?BIG5?B?s6+sRt5t?= m9421001 at gmail.com
Sun Sep 11 13:21:10 EDT 2005


Hi,all ITK user:

I want to read a meta image(.mhd) and write it to DICOM format.

This is my code for this question:

========================================================
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkMetaDataDictionary.h"
#include "itkMetaDataObject.h"
#include "itkGDCMImageIO.h"

#include <list>
#include <fstream>

int main(int ac, char* av[])
{

  if(ac < 3)
    {
    std::cerr << "Usage: " << av[0] << " InputMETAFile OutputDICOM\n";
    return EXIT_FAILURE;
    }

  typedef itk::Image<signed int, 3> ImageType;
  
  typedef itk::ImageFileReader< ImageType > VolumeReaderType;
  
  VolumeReaderType::Pointer reader = VolumeReaderType::New();

  reader->SetFileName( av[1] );
  
  try
    {
    reader->Update();	
    }
  catch (itk::ExceptionObject & e)
    {
    std::cerr << "exception in file reader " << std::endl;
    std::cerr << e.GetDescription() << std::endl;
    std::cerr << e.GetLocation() << std::endl;
    return EXIT_FAILURE;
    }


  typedef itk::GDCMImageIO        ImageIOType;	

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

  

  typedef itk::Image<short, 3> WriteType;
  typedef itk::ImageFileWriter<WriteType>	Writer1Type;
  Writer1Type::Pointer writer1=Writer1Type::New();
  
  writer1->SetFileName( av[2] );
  writer1->SetImageIO( gdcmImageIO );
  writer1->SetInput( reader->GetOutput() );

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

  return EXIT_SUCCESS;

}

========================================================
I get a error message as follows:

error C2664: 'SetInput' : cannot convert parameter 1 from 'class
itk::Image<int,3> *' to 'const class itk::Image<short,3> *'
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or function-style cast


My question is:

what format can specify when I  read a META image and write it to DICOM?


More information about the Insight-users mailing list