A script to extract an iso-surface from a DICOM series to produce an STL mesh.
Project description
dicom2stl
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:
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:
- Shrink ...the volume to 256 max dim (enabled by default)
- Anisotropic smoothing ...(disabled by default)
- Double threshold filter ...(enabled when tissue types are used)
- Median filter ...(enabled for 'soft' and 'fat' tissue types)
- Pad ...the volume
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:
- Extract a surface mesh ...from the VTK image
- Apply the clean mesh filter
- Remove small parts ...which connect to little other parts
- Apply the smooth mesh filter
- Apply the reduce mesh filter
- Write out an STL file
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dicom2stl-0.5.0.tar.gz
.
File metadata
- Download URL: dicom2stl-0.5.0.tar.gz
- Upload date:
- Size: 12.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb214135f811315203829abbc579cfdb8108d6af4fe49bd513620f4a4fae023d |
|
MD5 | 9f2da871697dff837986f81ef2b26afc |
|
BLAKE2b-256 | b219d624c5c868d12faa66b6c3efb9f2605ec03fe55fde2374870094513bb3ff |
File details
Details for the file dicom2stl-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: dicom2stl-0.5.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf0a6902e080721efab37d34ee8b0223fa7cc146ddb60e5248c14981fe6a2a5f |
|
MD5 | 3f0f0743e6cd5aa7ef0acad38684e221 |
|
BLAKE2b-256 | 99fceff9d0d553f9a80b05b515587fbc0664515b0232325e5dc326ae8465ed18 |