Dear ITK users,
I created a simple ITK program that reads a dicom slice and writes it back. The output generated dicom does not contain as many tags as the input dicom. Some tags are missing like 0008,1032. I don’t understand why.
Here is the source code of the program along with the dicom slice I used to test it and the output generated dicom:
#include “itkImage.h”
#include
// ITK
#include “itkImageFileReader.h”
#include “itkImageFileWriter.h”
#include “itkGDCMImageIO.h”
int main( int argc, char* argv[] )
{
if( argc != 2 ) {
std::cerr << "Usage: "<< std::endl;
std::cerr << argv[0];
std::cerr << " ";
std::cerr << std::endl;
return EXIT_FAILURE;
}
const char* inputDicomSliceFilename = argv[1];
typedef itk::Image< short, 2 > DicomInputImageType;
DicomInputImageType::Pointer image = DicomInputImageType::New();
// Reading input
typedef itk::ImageFileReader< DicomInputImageType > ReaderType;
typename ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputDicomSliceFilename);
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
reader->SetImageIO(gdcmImageIO);
try {
reader->Update();
}
catch (itk::ExceptionObject & e) {
std::cerr << "exception in file reader " << std::endl;
std::cerr << e << std::endl;
}
// Save
typedef itk::ImageFileWriter< DicomInputImageType > writerType;
typename writerType::Pointer writer = writerType::New();
writer->SetFileName("outputDicom");
writer->SetInput(reader->GetOutput());
writer->SetImageIO(gdcmImageIO);
try {
writer->Update();
}
catch (itk::ExceptionObject & e) {
std::cerr << "Exception in file writer " << std::endl;
std::cerr << e << std::endl;
}
return EXIT_SUCCESS;
}
CT000000AnonI.dcm (534.6 KB)
outputDicom (513.7 KB)