[Insight-users] Writing DICOM files, code attached
Invisible Human
itk_at_stanford at yahoo.com
Fri Apr 13 06:48:15 EDT 2007
Hi,
The following code outputs the raw volume correctly but the dicom volume is garbage although there are no exceptions or errors. Any pointers on whats lacking in this code will be appreciated.
Thanks,
Invisible Human.
-------------------------------------------------------------
void main(void){
typedef unsigned short PixelType;
const unsigned int Dimension = 3;
typedef itk::Image<PixelType,Dimension> ImageType;
const unsigned int OutputDimension = 2;
typedef itk::Image< PixelType, OutputDimension > Image2DType;
typedef itk::ImageSeriesWriter<ImageType, Image2DType > SeriesWriterType;
typedef itk::ImageFileWriter<ImageType> WriterType;
typedef itk::ImageSeriesReader<ImageType> ReaderType;
typedef itk::RawImageIO<PixelType,2> RawImageIOType;
typedef itk::RawImageIO<PixelType,3> Raw3DImageIOType;
typedef itk::GDCMImageIO GDCMIOType;
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
typedef itk::NumericSeriesFileNames NameGeneratorType;
NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
nameGenerator->SetSeriesFormat( "C:\\VolData\\2.99.3915.a%03d" );
nameGenerator->SetStartIndex( 0 );
nameGenerator->SetEndIndex( 874 );
nameGenerator->SetIncrementIndex( 1 );
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO(rawIO);
reader->SetFileNames(nameGenerator->GetFileNames());
GDCMIOType::Pointer gdcmIO = GDCMIOType::New();
gdcmIO->SetNumberOfComponents(1);
gdcmIO->SetDimensions(0,512);
gdcmIO->SetDimensions(1,512);
gdcmIO->SetDimensions(2,874);
RawImageIOType::Pointer rawIO = RawImageIOType::New();
rawIO->SetDimensions(0,512);
rawIO->SetDimensions(1,512);
rawIO->SetFileTypeToBinary();
rawIO->SetByteOrderToBigEndian();
Raw3DImageIOType::Pointer raw3DIO = Raw3DImageIOType::New();
raw3DIO->SetDimensions(0,512);
raw3DIO->SetDimensions(1,512);
raw3DIO->SetDimensions(2,874);
raw3DIO->SetFileTypeToBinary();
raw3DIO->SetByteOrderToBigEndian();
WriterType::Pointer dcmWriter = WriterType::New();
dcmWriter = WriterType::New();
dcmWriter->SetFileName("c:\\temp\\dpitk\\test.dcm");
dcmWriter->SetInput(reader->GetOutput());
dcmWriter->SetImageIO(gdcmIO);
WriterType::Pointer rawWriter = WriterType::New();
rawWriter = WriterType::New();
rawWriter->SetFileName("c:\\temp\\dpitk\\test.raw");
rawWriter->SetInput(reader->GetOutput());
rawWriter->SetImageIO(raw3DIO);
try{
reader->Update();
dcmWriter->Update();
rawWriter->Update();
}
catch(itk::ExceptionObject& e){
std::cerr << "Error reading the series " << std::endl;
std::cerr << e << std::endl;
}
}
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Insight-users
mailing list