[Insight-users] Conversion from DICOM to NIFTI
Daniele Domenichelli
daniele.domenichelli at gmail.com
Tue Apr 15 13:17:12 EDT 2008
Hello,
I'm trying to convert dicom images into nifti images, but i found some
strange behaviors
1) Nifti header is too big: it should be 348 bytes, but it is 352
bytes instead. This is the same for ".hdr" and for ".nii" files.
This does not happen if I use AnalyzeImageIO instead of NiftiImageIO
2) Orientation of the output nifti file is wrong. In the header For
example I have a coronal acquisition and converting it in nifti in the
header is saved as "LPS" but image is written as "LIP".
This is the code I'm using.
Am I doing something wrong?
I'm using the last ITK version...
Thanks,
Daniele Domenichelli
------
#include <itkDICOMImageIO2Factory.h>
#include <itkDICOMImageIO2.h>
#include <itkImageSeriesReader.h>
#include <itkDICOMSeriesFileNames.h>
#include <itkImageFileWriter.h>
#include <itkImageFileReader.h>
#include <itkImageIOFactory.h>
#include <itkNiftiImageIOFactory.h>
#include <itkNiftiImageIO.h>
#include <string>
int main(int argc, char* argv[])
{
if (argc!=4)
{
std::cout << "Usage: " << argv[0] << " <dicom_dir>
<output_filename> <reverse_order>" << std::endl;
return EXIT_FAILURE;
}
std::string m_DirectoryName = argv[1];
std::string m_OutputFileName = argv[2];
unsigned char m_ReverseOrder = atoi(argv[2]);
typedef itk::Image<unsigned short,3> DICOMImageType;
typedef itk::ImageSeriesReader<DICOMImageType> ReaderType;
itk::DICOMImageIO2::Pointer io = itk::DICOMImageIO2::New();
// Get the DICOM filenames from the directory
itk::DICOMSeriesFileNames::Pointer names = itk::DICOMSeriesFileNames::New();
names->SetDirectory(m_DirectoryName.c_str());
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileNames(names->GetFileNames());
reader->SetImageIO(io);
if (m_ReverseOrder)
{
reader->ReverseOrderOn();
}
typedef itk::ImageFileWriter<DICOMImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
typedef itk::NiftiImageIO OutImageIO;
OutImageIO::Pointer outImageIO = OutImageIO::New();
writer->SetImageIO(outImageIO);
writer->SetFileName(m_OutputFileName.c_str());
writer->SetInput( reader->GetOutput() );
try
{
reader->Update();
writer->Update();
writer->Write();
}
catch ( itk::ExceptionObject & ex )
{
std::string message;
message = ex.GetLocation();
message += "\n";
message += ex.GetDescription();
std::cerr << message << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
-------
More information about the Insight-users
mailing list