[ITK Community] reading/writing a single dicom
Andras Lasso
lasso at queensu.ca
Thu Jan 16 14:32:27 EST 2014
Hi Amber,
DCMTK can most probably read/modify/write these scout images. The easiest is to use the dcmodify tool (for more info google: dcmtk anonymize). You can download dcmodify or change the ITK build options to build/use DCMTK.
Andras
From: Community [mailto:community-bounces at itk.org] On Behalf Of Amber Simpson
Sent: Thursday, January 16, 2014 2:16 PM
To: community at itk.org
Subject: [ITK Community] reading/writing a single dicom
Hi All,
I'm attempting to anonymize a single Scout image in dicom format. The image should be written out to the same format to maintain compatibility with another software package. ImageJ, gdcmanon, and ITKsnap cannot read this dicom but OSIRIX can. The dicom header appears not to be readable with GDCMImageIO. The dicom can be read using a version of DicomPrintPatientInformation.cxx (from the ITK examples) that relies on DICOMImageIO2. I added a writer to the example but no file (dicom or otherwise) is generated. See below for code. Any suggestions on getting this code to work? Or should I take another approach entirely?
Thanks,
Amber
#include "itkDICOMImageIO2.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"
#include "itkMetaDataDictionary.h"
#include "itkMetaDataObject.h"
//#include "itkGDCMImageIO.h"
int main( int argc, char* argv[] )
{
if( argc < 2 )
{
std::cerr << "Usage: " << argv[0] << " DicomFile " << std::endl;
return EXIT_FAILURE;
}
typedef itk::Image<signed short,2> ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
itk::DICOMImageIO2::Pointer dicomIO = itk::DICOMImageIO2::New();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
reader->SetImageIO( dicomIO );
try
{
reader->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
const unsigned int length = 2048;
char patientName[ length ];
char patientID[ length ];
char patientSex[ length ];
char patientAge[ length ];
char studyDate[ length ];
char modality[ length ];
char manufacturer[ length ];
char institution[ length ];
char model[ length ];
dicomIO->GetPatientName( patientName );
dicomIO->GetPatientID( patientID );
dicomIO->GetPatientSex( patientSex );
dicomIO->GetPatientAge( patientAge );
dicomIO->GetStudyDate( studyDate );
dicomIO->GetModality( modality );
dicomIO->GetManufacturer( manufacturer );
dicomIO->GetInstitution( institution );
dicomIO->GetModel( model );
std::cout << "Before anonymization: " << std::endl;
std::cout << "Patient Name : " << patientName << std::endl;
std::cout << "Patient ID : " << patientID << std::endl;
std::cout << "Patient Sex : " << patientSex << std::endl;
std::cout << "Patient Age : " << patientAge << std::endl;
std::cout << "Study Date : " << studyDate << std::endl;
std::cout << "Modality : " << modality << std::endl;
std::cout << "Manufacturer : " << manufacturer << std::endl;
std::cout << "Institution : " << institution << std::endl;
std::cout << "Model : " << model << std::endl;
try
{
reader->Update();
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
std::cout << "Writing the image as " << std::endl << std::endl;
std::cout << "test_dicom.dcm" << std::endl << std::endl;
writer->SetFileName( "test_dicom.dcm" );
writer->SetInput( reader->GetOutput() );
try
{
writer->UpdateLargestPossibleRegion(); //changed from example
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140116/8564c290/attachment-0002.html>
More information about the Community
mailing list