I want to generate a mesh from an extracted volume of a CT scan.
I have extracted the volume as a binary array, which can be used as an input for the marching cubes algorithm of the scikit-image package. However, this function generates a surface mesh, and I need the inside of the mesh to be solid for the rest of my script to run properly. This is how I generate the mesh:
extractedVolume = extractVolume()
struct = ndimage.generate_binary_structure(3, 3)
closed = skimage.morphology.binary_closing(image=extractedVolume,footprint=struct)
opened = skimage.morphology.binary_opening(closed,struct)
median_filter = ndi.median_filter(opened,(5,5,5))
median_filter2 = ndi.median_filter(median_filter, (5,5,5))
mesh_verts,mesh_faces,mesh_normals,mesh_values = skimage.measure.marching_cubes(median_filter2, level=0,step_size=1)
faces_with_counts = np.hstack([np.full((mesh_faces.shape[0],1),3),mesh_faces])
mesh = pv.PolyData(mesh_verts,faces_with_counts)
largest = mesh.connectivity('largest')
I then edit this mesh in 3D:
grid = largest.cast_to_unstructured_grid()
#grid = mesh.cast_to_unstructured_grid()
#largest = grid.extract_largest()
plotter = pv.Plotter()
plotter.add_mesh(grid,color='blue')
plotter.enable_cell_picking(callback=testFunction,show=False)
plotter.show()
grid.plot()
This is the result I get, you can clearly see it’s hollow:
I have already tried to use the spacing and slice thickness of the CT scan as spacing
parameter for the marching cubes algorithm, but it lead to the same result. Would really appreciate it if somebody could help me!