title: stack of 2D images to 3D python
body: <p>I have 2D CT images in a 3D numpy of shape <code>[512, 512, 586]</code> (or a bunch of jpeg files saved from this array). Those images have only two pixels values: 0 or 255</p>
  
  <p>what I need to do is to convert this array into a printable 3D model/mesh (STL or whatever is possible)</p>
  
  <p><a href="https://stackoverflow.com/questions/30237024/operate-on-slices-of-3d-image-in-simpleitk-and-create-new-3d-image">I tried what was described in this post</a> using simple itk. However I didn't find anything about saving the volume into a stl file</p>
  
  <p>is there a way to do this? (using simple itk or any other library)</p>
  
  <p>--EDIT--
  so here is my code using VTK, however i'm having trouble to convert the numpy array to a vtk array</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>this code is showing a black window with nothing inside it</p>
  
  <p>The other code:</p>
  
  <pre><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)
  </code></pre>
  
  <p>this one is getting the error :
  TypeError: no overloads of SetInputData() take 0 arguments</p>