[Insight-users] Problem with conversion dicom -> .vtk file

Luis Ibanez luis.ibanez at kitware.com
Sat Feb 19 16:24:14 EST 2011


Hi Agata,

In order to convert a DICOM series to a surface you need to do the following
major steps

1) Read the DICOM series into a 3D Image
2) Run a segmentation method
3) Convert the resulting 3D segmented image to VTK
4) Use the vtkContour filter to extract the iso-surface around the segmentation
5) Save the surface to a .vtk file using the vtkPolyDataWriter.


You will find an example of step (1) in

      ITK/Examples/IO/
        DicomSeriesReadImageWrite2.cxx


and you will find an example on steps (2,3,4,5) in

      ITKApps/Auxiliary/vtk/
          itkReadITKImage3DSegmentShowVTK.cxx


Note that the segmentation illustrated there is a simple region growing method.
Depending on the anatomical structures that you want to extract, and the
characteristics of the DICOM image that you have, you may have to apply
different segmentation methods.


There is a large variety of them in ITK that you can try.


Please let us know if you have further questions.


    Thanks


      Luis


------------------------------------------------
On Fri, Feb 18, 2011 at 2:52 PM, agata <agatakrason at gmail.com> wrote:
>
>  Hello All ITK-Users ;)
>
>
>  I 'm writing my first program  with ITK ..
> I'm fresh user of ITK . I ' m beging my adventure with itk . ..
>  I need to convert dcm series to .vtk file (as surface  vtkPolyData)
>
>
> I wrote code , it compiles good  but when I open a file I receive wrog data
> . I think that it's a problem with mesh ? could You look at my code please
> ???
> --------------------------------------------------------
> # vtk DataFile Version 2.0
> File written by itkVTKPolyDataWriter
> ASCII
> DATASET POLYDATA
> POINTS 0 float
> ---------------------------------------------------------
>
>
> If it 's possible Could You help me please ?
>
>
>  #include <iostream>
> #include <cstdlib>
>
>
> #include "itkImage.h"
> #include "itkGDCMImageIO.h"
> #include "itkGDCMSeriesFileNames.h"
> #include "itkImageSeriesReader.h"
> #include "itkImageFileWriter.h"
>
> #include "itkMesh.h"
> #include "itkImage.h"
> #include "itkCovariantVector.h"
> #include "itkImageFileReader.h"
> #include "itkVTKImageIO.h"
> #include "itkBinaryMask3DMeshSource.h"
> #include "itkVTKPolyDataWriter.h"
>
> #include <vector>
> #include <itksys/SystemTools.hxx>
>
> int main()
> {
>
>
>  typedef signed short PixelType;
>  const unsigned int Dimension = 3;
>
>  typedef itk::Image<PixelType, Dimension> ImageType;
>  typedef itk::ImageSeriesReader<ImageType> ReaderType;
>
>  typedef itk::GDCMImageIO ImageIOType;
>  typedef itk::GDCMSeriesFileNames NamesGeneratorType;
>
>  ImageIOType::Pointer gdcmIO = ImageIOType::New();
>  NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
>
>
>  std::string folderWE;
>  std::cout<<" path to directory : "<<std::endl;
>  std::cin>>folderWE;
>  namesGenerator->SetInputDirectory(folderWE);
>
>  const ReaderType::FileNamesContainer &filenames =
> namesGenerator->GetInputFileNames();
>
>  unsigned int numberOfFilenames = filenames.size();
>  std::cout<<numberOfFilenames <<std::endl;
>
>  for(unsigned int fni = 0; fni < numberOfFilenames; fni++)
>  {
>  std::cout<<"filename # "<<fni << " = ";
>  std::cout<<filenames[fni] <<std::endl;
>  }
>
>
>  ReaderType::Pointer reader = ReaderType::New();
>
>  reader->SetImageIO(gdcmIO);
>  reader->SetFileNames(filenames);
>
>  // read dicom series
>  try
>  {
>  reader->Update();
>  }
>  catch(itk::ExceptionObject &excp)
>  {
>  std::cerr<<" Exception .."<<std::endl;
>  std::cerr<<excp<<std::endl;
>  }
>
>
>
>
>  // create mesh ..
>  /// I don't know here  ????
>  typedef float MeshPixelType;
>  typedef itk::Mesh<MeshPixelType,Dimension> MeshType;
>  typedef itk::BinaryMask3DMeshSource<ImageType, MeshType> MeshSourceType; //
> ???
>
>  MeshSourceType::Pointer meshSource = MeshSourceType::New();
>  const PixelType objectValue = static_cast<PixelType>(1250);
>
>  meshSource->SetObjectValue(objectValue);
>  meshSource->SetInput(reader->GetOutput());
>
>  // write *.vtk
>
>  meshSource->Update();
>  MeshType::Pointer mesh = meshSource->GetOutput();
>
>  typedef itk::VTKPolyDataWriter<MeshType> WriterType;
>  WriterType::Pointer writer = WriterType::New();
>    writer->SetInput(mesh);
>
>  std::string fileVTK;
>  std::cout<<"save as  *.vtk:  "<<std::endl;
>  std::cin>>fileVTK;
>  writer->SetFileName(fileVTK);
>
>  //writer->SetInput(reader->GetOutput());
>  try
>  {
>  writer->Update();
>  }
>  catch(itk::ExceptionObject &excp)
>  {
>  std::cerr<<"Exception Object !"<<std::endl;
>  std::cerr<<excp<<std::endl;
>  return EXIT_FAILURE;
>  }
>
>
>
>  return EXIT_SUCCESS;
>
>
> }
>
> I would appreciate for any help .
>
>
>
> Best,
> Agata
> --
> View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Problem-with-conversion-dicom-vtk-file-tp6041275p6041275.html
> Sent from the ITK Insight Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list