0

Given a vtk image:


vtkSmartPointer<vtkImageData> VTKImage = vtkSmartPointer<vtkImageData>::New();


which is a 3D image that contains a segmentation result as binary data (segmented object = 1, background = 0), How could I extract the surface of the segmented object and save it as VTKpolyData?

Sonnenschein
  • 169
  • 7
  • 21

2 Answers2

5

A minimal working example would be something like this.

vtkSmartPointer<vtkMarchingCubes> surface = 
vtkSmartPointer<vtkMarchingCubes>::New();

#if VTK_MAJOR_VERSION <= 5
surface->SetInput(volume);
#else
surface->SetInputData(volume);
#endif
surface->SetValue(0, 0.5);
surface->Update();

vtkSmartPointer<vtkPolyData> poly = vtkSmartPointer<vtkPolyData>::New();
poly = surface->GetOutput();
g.stevo
  • 745
  • 3
  • 10
  • l folllowed the steps found here(https://pyscience.wordpress.com/2014/09/11/surface-extraction-creating-a-mesh-from-pixel-data-using-python-and-vtk/) and got the same result. What is the difference between **vtkmarchingcubes** and **vtkdiscretemarchingcubes**? – Sonnenschein May 16 '16 at 16:49
  • 1
    When it comes to 2d image and polygon, you may refer to `vtkMarchingSquares` which is the 2d marching cube. – Summer Sun Mar 16 '17 at 12:03
  • Thanks a lot this is so useful – sc241 Nov 08 '19 at 16:34
2

Use vtkMarchingCubes class. there are some examples here and here

Afshin
  • 392
  • 2
  • 11