[Insight-users] strange dicom output file

Ming Chao mingchao2005 at gmail.com
Wed Nov 4 10:38:55 EST 2009


Hi ITKers.

Recently I was asking questions here about how to write out an multiframe
dicom file. Thanks for all the help.

As a matter of fact, it is not so hard to save a 3D volumetric image into a
multiframe dicom file. Please see the attached code. But I do encounter a
problem in the output dicom file. Basically the range of the voxel values of
the output file  much narrower than expected ( I attached the images from
the output dicom and original dicom). I double checked the data types and
they seemed fine. Could anyone help? thanks.

Ming


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

// Verify the number of parameters in the command line
if( argc < 4 ) {
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " vtkImage InputDicomImage ";
std::cerr << " OutputImage \n";
return EXIT_FAILURE;
    }

// the following is for an input 2D dicom file
typedef unsigned short InputPixelType;
const unsigned int   InputDimension = 3;
typedef itk::Image< InputPixelType, InputDimension > InputImageType;

typedef itk::ImageFileReader< InputImageType > InputReaderType;
InputReaderType::Pointer reader1 = InputReaderType::New();
reader1->SetFileName( argv[1] );
 typedef itk::GDCMImageIO          InputImageIOType;
InputImageIOType::Pointer gdcmImageIO = InputImageIOType::New();
reader1->SetImageIO( gdcmImageIO );
reader1->Update();

std::cout << " (1) first dicom file is read in successfully ...." <<
std::endl;

 // The following is a print out of the tag info
typedef itk::MetaDataDictionary   DictionaryType;
const  DictionaryType & dictionary = gdcmImageIO->GetMetaDataDictionary();
typedef itk::MetaDataObject< std::string > MetaDataStringType;

DictionaryType::ConstIterator itr = dictionary.Begin();
DictionaryType::ConstIterator end = dictionary.End();

while( itr != end )
    {
itk::MetaDataObjectBase::Pointer  entry = itr->second;

MetaDataStringType::Pointer entryvalue =
dynamic_cast<MetaDataStringType *>( entry.GetPointer() ) ;

if( entryvalue )
{
std::string tagkey   = itr->first;
std::string tagvalue = entryvalue->GetMetaDataObjectValue();
std::cout << tagkey <<  " = " << tagvalue << std::endl;
}

++itr;
    }

// the following is for a 3D volume file
typedef float PixelType;
const unsigned int   Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;

typedef itk::ImageFileReader< ImageType  >  ReaderType;
    ReaderType::Pointer reader2 = ReaderType::New();
    reader2->SetFileName( argv[2] );
reader2->Update();

std::cout << " (2) the 3D volume file is read in successfully ...." <<
std::endl;

    // the following is for an output 3D dicom file
 typedef float OutputPixelType;
const unsigned int   OutputDimension = 3;
typedef itk::Image< OutputPixelType, OutputDimension > OutputImageType;

typedef itk::ImageSeriesWriter< ImageType, OutputImageType >
OutputWriterType;
OutputWriterType::Pointer writer = OutputWriterType::New();
writer->SetFileName( argv[3] );
 writer->SetInput( reader2->GetOutput() );

 writer->SetMetaDataDictionary( reader1->GetMetaDataDictionary() );
gdcmImageIO->KeepOriginalUIDOn();
writer->SetImageIO( gdcmImageIO );

writer->Update();

std::cout << " (3) the output dicom file is saved successfully and we are
done...." << std::endl;


return 0;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091104/f9423256/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: originaldicom.GIF
Type: image/gif
Size: 13980 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091104/f9423256/attachment-0002.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: outputdicom.GIF
Type: image/gif
Size: 13430 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091104/f9423256/attachment-0003.gif>


More information about the Insight-users mailing list