[Insight-users] DICOM series loading and visulization

Xiaopeng Yang yxp233 at postech.ac.kr
Mon Jul 12 23:56:30 EDT 2010


Dear all,

 

I am trying to load a series of DICOM images and visualizing them through
VTK. Although I loaded several files, the VTK just visualized one image.
What I want is to visualize all of them through VTK, not just one file. It
is better that if I scroll the mouse wheel, I can review them slice by
slice. Anyone have the experience of doing this? Could you provide an
example code?

 

Attached is my code:

 

  //Define image parameters

  typedef    float    InputPixelType;

  typedef    float    OutputPixelType;

  typedef itk::Image< InputPixelType,  3 >   InputImageType;

  typedef itk::Image< OutputPixelType, 3 >   OutputImageType;

 

  // Load DICOM files

  typedef itk::ImageSeriesReader< InputImageType >     ReaderType;

  ReaderType::Pointer reader = ReaderType::New();

  typedef itk::GDCMImageIO                        ImageIOType;

  typedef itk::GDCMSeriesFileNames                NamesGeneratorType;

 

  ImageIOType::Pointer gdcmIO = ImageIOType::New();

  NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();

  

  namesGenerator->SetInputDirectory( "C:/test" );

 

  const ReaderType::FileNamesContainer & filenames = 

                            namesGenerator->GetInputFileNames();

 

  unsigned int numberOfFilenames =  filenames.size();

  std::cout << numberOfFilenames << " images loaded" << std::endl; 

  for(unsigned int fni = 0; fni<numberOfFilenames; fni++)

    {

    std::cout << "filename # " << fni << " = ";

    std::cout << filenames[fni] << std::endl;

    }

 

  reader->SetImageIO( gdcmIO );

  reader->SetFileNames( filenames );

 

  typedef itk::ImageToVTKImageFilter<InputImageType>FilterType;

  FilterType::Pointer connector = FilterType::New();

 

  try

    {

    reader->Update();

    }

  catch (itk::ExceptionObject &ex)

    {

    std::cout << ex << std::endl;

    return EXIT_FAILURE;

    }

 

  connector->SetInput(reader->GetOutput());

 

  vtkImageViewer *viewer = vtkImageViewer::New();

  vtkRenderWindowInteractor *renderWindowInteractor =
vtkRenderWindowInteractor::New();

 

  viewer->SetupInteractor(renderWindowInteractor);

  viewer->SetInput(connector->GetOutput());

  viewer->Render();

  viewer->SetColorWindow(255);

  viewer->SetColorLevel(128);

 

  renderWindowInteractor->Start();

 

return 0;

 

 

Thank you very much!

Xiaopeng

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100713/18637476/attachment-0001.htm>


More information about the Insight-users mailing list