[Insight-users] Re: conversion of 16-bit Dicom image data to .vtk format...?
Luis Ibanez
luis . ibanez at kitware . com
Mon, 13 Oct 2003 09:56:54 -0400
This is a multi-part message in MIME format.
--------------090805070107010106000600
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hi Sowjanya,
The attached code will convert DICOM data to VTK format.
This is a modified version of the test in
Insight/Testing/Code/IO/itkDICOMImageSeriesTest.cxx
This will take a directory as input. If you have several
DICOM series in the same directory, you will have to select
one of the series first.
(Note that you may want to replace "unsigned short" with
"signed short" depending on the nature of your data...)
Regards,
Luis
----------------------------------------------------------------
V, Sowjanya (CORP, GEITC, Intern) wrote:
> Hi,
>
> I need to convert my Dicom Image data (16-bit) to .vtk format.
> Can you plz suggest me some method for this.
>
> Thanku,
> Sowjanya
>
>
>
-----------------------------------------------------------------
--------------090805070107010106000600
Content-Type: text/plain;
name="DICOM2VTK.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="DICOM2VTK.cxx"
#include "itkDICOMImageIO2.h"
#include "itkImageSeriesReader.h"
#include "itkDICOMSeriesFileNames.h"
#include "itkImageFileWriter.h"
int main( int argc, char* argv[] )
{
if( argc < 2 )
{
std::cerr << "Usage: " << argv[0] << " DicomDirectory " << std::endl;
return EXIT_FAILURE;
}
typedef itk::Image<unsigned short,3> ImageType;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
itk::DICOMImageIO2::Pointer io = itk::DICOMImageIO2::New();
// Get the DICOM filenames from the directory
itk::DICOMSeriesFileNames::Pointer nameGenerator = itk::DICOMSeriesFileNames::New();
nameGenerator->SetDirectory( argv[1] );
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileNames( nameGenerator->GetFileNames());
reader->SetImageIO(io);
try
{
reader->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex;
return EXIT_FAILURE;
}
itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = Writer::New();
writer->SetFileName("Image.vtk");
writer->SetInput( reader->GetOutput() );
try
{
writer->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex;
return EXIT_FAILURE;
}
return 0;
}
--------------090805070107010106000600--