Skip to main content

dicom2stl

Binder Python application

Tutorial: Binder

dicom2stl is a script that takes a Dicom series and generates a STL surface mesh.

Written by David T. Chen from the National Institute of Allergy & Infectious Diseases (NIAID), dchen@mail.nih.gov It is covered by the Apache License, Version 2.0:

http://www.apache.org/licenses/LICENSE-2.0

Getting Started

The script is written in Python and uses 4 external packages, SimpleITK, SimpleITKUtilities, VTK, and pydicom.

dicom2stl and its dependencies can be installed using pip:

pip install dicom2stl

The options for the main script, dicom2stl, can be seen by running it:

dicom2stl --help

Once you have a DICOM image series zip you can run your first script (Ensure that the ".zip" file is in the dicom2stl directory):

dicom2stl -t tissue -o output.stl dicom.zip

This will create a .stl file named "output.stl" that extracted tissue from the DICOM image series.

How dicom2stl works

The script starts by reading in a series of 2-d images or a simple 3-d image. It can read any format supported by ITK. If the input name is a zip file or a directory name, the script expects a single series of DCM images, all with the ".dcm" suffix.

Note: if this script is run with the individual Dicom slices provided on the command line, the slices might not be ordered in the correct order. It is better to provide a zip file or a directory, so ITK can determine the proper slice ordering. Dicom slices are not necessarily ordered the same alphabetically as they are physically. In the case of a zip file or directory, the script loads using the SimpleITK ImageSeriesReader class, which orders the slices by their physical layout, not their alphabetical names.

The primary image processing pipeline is as follows:

The script has built in double threshold values for the 4 different tissue types (bone, skin, muscle, soft). These values assume the input is DICOM with standard CT Hounsfield units. I determined these values experimentally on a few DICOM test sets, so the values might not work as well on other images.

The volume is shrunk to 256 cubed or less for speed and polygon count reasons.

After all the image processing is finished, the volume is converted to a VTK image using sitk2vtk from SimpleITKUtilities.

Then the following VTK pipeline is executed:

The amount of smoothing and mesh reduction can be adjusted via command line options. By default 25 iterations of smoothing is applied and the number of vertices is reduced by 90%.

Basic Usage & Options

usage: dicom2stl [-h] [--verbose] [--debug] [--output OUTPUT] [--meta META] [--ct] [--clean] [--temp TEMP] [--search SEARCH]
                    [--type {skin,bone,soft_tissue,fat}] [--anisotropic] [--isovalue ISOVALUE] [--double DOUBLE_THRESHOLD] [--largest]
                    [--rotaxis {X,Y,Z}] [--rotangle ROTANGLE] [--smooth SMOOTH] [--reduce REDUCE] [--clean-small SMALL]
                    [--enable {anisotropic,shrink,median,largest,rotation}] [--disable {anisotropic,shrink,median,largest,rotation}]
                    [filenames ...]

For a definitive list of options, run:

dicom2stl --help

Examples

To extract the type "bone" from a zip of dicom images to an output file "bone.stl":

dicom2stl -t bone -o bone.stl dicom.zip

To extract the skin from a NRRD volume:

dicom2stl -t skin -o skin.stl volume.nrrd

To extract a specific iso-value (128) from a VTK volume:

dicom2stl -i 128 -o iso.stl volume.vtk

To extract soft tissue from a dicom series in directory and apply a 180 degree Y axis rotation:

dicom2stl --enable rotation -t soft_tissue -o soft.stl dicom_dir

The options for the script can be seen by running it:

dicom2stl --help

You can try out an interactive Jupyter notebook via Binder: Binder

Metadata

Release files for dicom2stl 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dicom2stl 0.5.0
File Size Uploaded
dicom2stl-0.5.0.tar.gz 12.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for dicom2stl 0.5.0
File Interpreter ABI Platform
dicom2stl-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 MB

Release files / dicom2stl-0.5.0.tar.gz

Download URL dicom2stl-0.5.0.tar.gz
Size 12.0 MB
Tags Source
SHA-256 checksum
How to use checksums
fb214135f811315203829abbc579cfdb8108d6af4fe49bd513620f4a4fae023d
BLAKE2b-256 checksum
How to use checksums
b219d624c5c868d12faa66b6c3efb9f2605ec03fe55fde2374870094513bb3ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / dicom2stl-0.5.0-py3-none-any.whl

Download URL dicom2stl-0.5.0-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf0a6902e080721efab37d34ee8b0223fa7cc146ddb60e5248c14981fe6a2a5f
BLAKE2b-256 checksum
How to use checksums
99fceff9d0d553f9a80b05b515587fbc0664515b0232325e5dc326ae8465ed18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page