[Insight-users] Convert raw image to dicom using itk

junhui wang mskccvb at yahoo.com
Thu Jul 7 18:54:26 EDT 2005


Hi,

I tried to Convert raw image to dicom using itk based
on Example/IO/DicomSeriesReadSeriesWrite.cxx (The
input is raw file not dicom).  I wrote the following
code:

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

	typedef float PixelType;
	const unsigned char Dimension=3;
	typedef itk::Image<PixelType,Dimension> ImageType;
	
	typedef itk::ImageFileReader<ImageType> ReaderType;
	typedef itk::GDCMImageIO				ImageIOType;
	typedef itk::GDCMSeriesFileNames		SeriesFileNames;
	ImageIOType::Pointer gdcmIO=ImageIOType::New();
	SeriesFileNames::Pointer it=SeriesFileNames::New();
	
	ReaderType::Pointer reader = ReaderType::New();
	reader->SetFileName(argv[1]);
	reader->SetImageIO(gdcmIO);
	try
	{
		reader->Update();
	}
	catch (itk::ExceptionObject & excp) 
	{
		std::cerr<<"error:"<<excp<<std::endl;
		return 1;
	}

	ImageType::Pointer rawImage=ImageType::New();
	//access to newly read image
	rawImage=reader->GetOutput();
	ImageType::SizeType
rawImageSize=rawImage->GetLargestPossibleRegion().GetSize();
	const int rawImageDims[3]={rawImageSize[0],
rawImageSize[1], rawImageSize[2]};
	const double
*rawImageSpacing=rawImage->GetSpacing().GetDataPointer();


  const char * outputDirectory = argv[2];

  itksys::SystemTools::MakeDirectory( outputDirectory
);
    
  typedef itk::Image<unsigned short,2>           
Image2DType;
  //typedef itk::Image<float,2>           
Image2DType;
  typedef itk::ImageSeriesWriter< ImageType,
Image2DType > SeriesWriterType;
    
  SeriesWriterType::Pointer swriter =
SeriesWriterType::New();
  swriter->SetInput( reader->GetOutput() );
  swriter->SetImageIO( gdcmIO );

  it->SetOutputDirectory( outputDirectory );
  swriter->SetFileNames( it->GetOutputFileNames() );


//  The next line is extremely important for this
process to work correctly.
//  The line is taking the MetaDataDictionary from the
input reader and passing
//  it to the output writer. The reason why this step
is so important is that
//  the MetaDataDictionary contains all the entries of
the input DICOM header.
//
//  Software Guide : EndLatex 

// Software Guide : BeginCodeSnippet
  swriter->SetMetaDataDictionaryArray(
reader->GetMetaDataDictionaryArray() );
  
  // Try to write the series:
  try
    {
    swriter->Update();
    }
  catch( itk::ExceptionObject & excp )
    {
    std::cerr << "Exception thrown while writing the
series " << std::endl;
    std::cerr << excp << std::endl;
    }


  return EXIT_SUCCESS;
}

But when compiling, give the following error:
Compiling...
RawToDicom.cxx
E:\Projects\Deform_Reg\itk_Test\RawToDicom\RawToDicom.cxx(152)
: error C2039: 'GetMetaDataDictionaryArray' : is not a
member of 'ImageFileReader<class
itk::Image<float,3>,class
itk::DefaultConvertPixelTraits<float> >'
Error executing cl.exe.
Creating browse info file...

RawToDicom.exe - 1 error(s), 0 warning(s)

Can anybody tell me what's wrong?

Thanks in advance.

Albert

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An embedded message was scrubbed...
From: junhui wang <mskccvb at yahoo.com>
Subject: [Insight-users] Convert raw image to dicom using itk
Date: Wed, 6 Jul 2005 09:38:00 -0700 (PDT)
Size: 3155
Url: http://public.kitware.com/pipermail/insight-users/attachments/20050707/0dc5219f/attachment.mht


More information about the Insight-users mailing list