dark1sider
dark1sider

Reputation: 45

How to turn CT segmentation into 3d model in python

I have this numpy array of slices of segments of the liver CT(ground truths). I want to export them into a viewable format in tools like blender. The slices are white and black, 0-255. Anything other than liver is black, I want the liver to be viewed in 3d.

The slices are in top view. I used this code in kaggle to view them but just in jupyter https://www.kaggle.com/akh64bit/full-preprocessing-tutorial/data. It can be any way to visualize them.

Upvotes: 0

Views: 2202

Answers (2)

Gus B
Gus B

Reputation: 297

For new folks stumbling upon this question that are looking to convert pixels / voxels to an STL file or files, this Python workflow has worked for me:

  1. Load stack of images as a 3D NumPy array using imageio.imread().
  2. Segment the foreground from the background using one of the many segmentation algorithms from the scikit-image submodule skimage.segmentation, creating a 3D binary image.
  3. Use the marching cubes algorithm from the scikit-image submodule skimage.measure to convert the voxels of interest to a list of faces defined by vertices on the surface of the volume.
  4. Use numpy-stl to create an stl.Mesh object from the list of faces and vertices (as done in this example) then save the mesh with stl.Mesh.save().

As a bonus, you can use the Python package for the Open3D library to open & view multiple STL files!

Upvotes: 1

Barış Akın
Barış Akın

Reputation: 147

You may try transform your arrays to DICOM format as mentioned before in stackoverflow: Create pydicom file from numpy array

Than you can easily visualize DICOM images in various platforms!

Upvotes: 1

Related Questions