<span class="Apple-style-span" style="font-family: arial, sans-serif, 'Arial Unicode MS'; font-size: 13px; border-collapse: collapse; ">Hi ITKers.<div><br></div><div>Recently I was asking questions here about how to write out an multiframe dicom file. Thanks for all the help. </div>
<div><br></div><div>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.</div>
<div><br></div><div>Ming</div><div><br></div><div><br></div><div><div>int main( int argc, char* argv[] ) {</div><div><br></div><div><span style="white-space: pre; ">        </span>// Verify the number of parameters in the command line</div>
<div><span style="white-space: pre; ">        </span>if( argc < 4 ) {</div><div><span style="white-space: pre; ">                </span>std::cerr << "Usage: " << std::endl;</div><div><span style="white-space: pre; ">                </span>std::cerr << argv[0] << " vtkImage InputDicomImage ";</div>
<div><span style="white-space: pre; ">                </span>std::cerr << " OutputImage \n";</div><div><span style="white-space: pre; ">                </span>return EXIT_FAILURE;</div><div> }</div><div><br></div><div><span style="white-space: pre; ">        </span>// the following is for an input 2D dicom file</div>
<div><span style="white-space: pre; ">        </span>typedef unsigned short InputPixelType;</div><div><span style="white-space: pre; ">        </span>const unsigned int InputDimension = 3;</div><div><span style="white-space: pre; ">        </span>typedef itk::Image< InputPixelType, InputDimension > InputImageType;</div>
<div><br></div><div><span style="white-space: pre; ">        </span>typedef itk::ImageFileReader< InputImageType > InputReaderType;</div><div><span style="white-space: pre; ">        </span>InputReaderType::Pointer reader1 = InputReaderType::New();</div>
<div><span style="white-space: pre; ">        </span>reader1->SetFileName( argv[1] );</div><div><span style="white-space: pre; ">        </span></div><div><span style="white-space: pre; ">        </span>typedef itk::GDCMImageIO InputImageIOType;</div>
<div><span style="white-space: pre; ">        </span>InputImageIOType::Pointer gdcmImageIO = InputImageIOType::New();</div><div><span style="white-space: pre; ">        </span>reader1->SetImageIO( gdcmImageIO );</div><div><span style="white-space: pre; ">        </span>reader1->Update();</div>
<div><br></div><div><span style="white-space: pre; ">        </span>std::cout << " (1) first dicom file is read in successfully ...." << std::endl;</div><div><br></div><div><span style="white-space: pre; ">        </span></div>
<div><span style="white-space: pre; ">        </span>// The following is a print out of the tag info</div><div><span style="white-space: pre; ">        </span>typedef itk::MetaDataDictionary DictionaryType;</div><div><span style="white-space: pre; ">        </span>const DictionaryType & dictionary = gdcmImageIO->GetMetaDataDictionary();</div>
<div><span style="white-space: pre; ">        </span>typedef itk::MetaDataObject< std::string > MetaDataStringType;</div><div><br></div><div><span style="white-space: pre; ">        </span>DictionaryType::ConstIterator itr = dictionary.Begin();</div>
<div><span style="white-space: pre; ">        </span>DictionaryType::ConstIterator end = dictionary.End();</div><div><br></div><div><span style="white-space: pre; ">        </span>while( itr != end )</div><div> {</div><div><span style="white-space: pre; ">                </span>itk::MetaDataObjectBase::Pointer entry = itr->second;</div>
<div><br></div><div><span style="white-space: pre; ">                </span>MetaDataStringType::Pointer entryvalue = </div><div><span style="white-space: pre; ">                        </span>dynamic_cast<MetaDataStringType *>( entry.GetPointer() ) ;</div>
<div><br></div><div><span style="white-space: pre; ">                </span>if( entryvalue )</div><div><span style="white-space: pre; ">                </span>{</div><div><span style="white-space: pre; ">                        </span>std::string tagkey = itr->first;</div>
<div><span style="white-space: pre; ">                        </span>std::string tagvalue = entryvalue->GetMetaDataObjectValue();</div><div><span style="white-space: pre; ">                        </span>std::cout << tagkey << " = " << tagvalue << std::endl;</div>
<div><span style="white-space: pre; ">                </span>}</div><div><br></div><div><span style="white-space: pre; ">                </span>++itr;</div><div> }</div><div><br></div><div><span style="white-space: pre; ">        </span>// the following is for a 3D volume file</div>
<div><span style="white-space: pre; ">        </span>typedef float PixelType;</div><div><span style="white-space: pre; ">        </span>const unsigned int Dimension = 3;</div><div><span style="white-space: pre; ">        </span>typedef itk::Image< PixelType, Dimension > ImageType;</div>
<div><br></div><div><span style="white-space: pre; ">        </span>typedef itk::ImageFileReader< ImageType > ReaderType;</div><div> ReaderType::Pointer reader2 = ReaderType::New();</div><div> reader2->SetFileName( argv[2] );</div>
<div><span style="white-space: pre; ">        </span>reader2->Update();</div><div><br></div><div><span style="white-space: pre; ">        </span>std::cout << " (2) the 3D volume file is read in successfully ...." << std::endl;</div>
<div><br></div><div> // the following is for an output 3D dicom file</div><div><span style="white-space: pre; ">        </span></div><div><span style="white-space: pre; ">        </span>typedef float OutputPixelType;</div><div><span style="white-space: pre; ">        </span>const unsigned int OutputDimension = 3;</div>
<div><span style="white-space: pre; ">        </span>typedef itk::Image< OutputPixelType, OutputDimension > OutputImageType;</div><div><br></div><div><span style="white-space: pre; ">        </span>typedef itk::ImageSeriesWriter< ImageType, OutputImageType > OutputWriterType;</div>
<div><span style="white-space: pre; ">        </span>OutputWriterType::Pointer writer = OutputWriterType::New();</div><div><span style="white-space: pre; ">        </span>writer->SetFileName( argv[3] );</div><div><span style="white-space: pre; ">        </span></div>
<div><span style="white-space: pre; ">        </span>writer->SetInput( reader2->GetOutput() );</div><div><br></div><div><span style="white-space: pre; ">        </span></div><div><span style="white-space: pre; ">        </span>writer->SetMetaDataDictionary( reader1->GetMetaDataDictionary() );</div>
<div><span style="white-space: pre; ">        </span>gdcmImageIO->KeepOriginalUIDOn();</div><div><span style="white-space: pre; ">        </span>writer->SetImageIO( gdcmImageIO );</div><div><span style="white-space: pre; ">        </span></div>
<div><br></div><div><span style="white-space: pre; ">        </span>writer->Update();</div><div><br></div><div><span style="white-space: pre; ">        </span>std::cout << " (3) the output dicom file is saved successfully and we are done...." << std::endl;</div>
<div><br></div><div><br></div><div><span style="white-space: pre; ">        </span>return 0;</div><div><br></div></div></span>