0

I have 2D CT images in a 3D numpy of shape [512, 512, 586] (or a bunch of jpeg files saved from this array). Those images have only two pixels values: 0 or 255

what I need to do is to convert this array into a printable 3D model/mesh (STL or whatever is possible)

I tried what was described in this post using simple itk. However I didn't find anything about saving the volume into a stl file

is there a way to do this? (using simple itk or any other library)

--EDIT-- so here is my code using VTK, however i'm having trouble to convert the numpy array to a vtk array

dataImporter = vtk.vtkImageImport()

data_string = ArrayDicom.tostring()

dataImporter.CopyImportVoidPointer(data_string, len(data_string))

dataImporter.SetDataScalarTypeToUnsignedShort()

dataImporter.SetNumberOfScalarComponents(1)

dataImporter.SetDataExtent(0, heightArray-1, 0, depthArray-1, 0, widthArray-1)
dataImporter.SetWholeExtent(0, heightArray-1, 0, depthArray-1, 0, widthArray-1)

this code is showing a black window with nothing inside it

The other code:

print("converting numpy array to VTK array")
CT_Data = reader.GetOutput()
NP_data = numpy_support.numpy_to_vtk(ArrayDicom.ravel(), deep=True, array_type=vtk.VTK_TYPE_INT16)

print("loading vtkImageData")
imageVTK = vtk.vtkImageData()
imageVTK.SetSpacing(CT_Data.GetSpacing())
imageVTK.SetOrigin(CT_Data.GetOrigin())
imageVTK.SetDimensions(CT_Data.GetDimensions())
imageVTK.GetPointData().SetScalars(NP_data)

dmc = vtk.vtkDiscreteMarchingCubes
dmc.SetInputData(imageVTK)

this one is getting the error : TypeError: no overloads of SetInputData() take 0 arguments

yatu
  • 86,083
  • 12
  • 84
  • 139
Mael Abgrall
  • 441
  • 2
  • 6
  • 16

1 Answers1

1

You have read a 3d image or volume. The STL file format is for polygonal meshes as far as I know. You need to do a segmentation of what is of interest in the volume, then do a surface extraction with something like marching cube, Then clean up the mesh for printing, then you can save it as s STL file for printing.

You may want to look into using VTK for the mesh manipulation or an application like Slicer3D.

blowekamp
  • 1,401
  • 7
  • 7
  • hey ! thank you for your quick answer Actually I've been on the subject for nearly two months I've followed a lot of example using discrete marching cube or raycasting. However I may do something wrong because it's not working. I guess it's during the numpy array convertion to vtk array I'll edit the post with my code – Mael Abgrall Mar 12 '18 at 08:15