Skip to main content

A python package for DICOM to NifTi and NifTi to DICOM-SEG and GSPS conversion

Project description

Nekton

Python Application TestingTest and Release Python VersionsPackage version

A python package for DICOM to NifTi and NifTi to DICOM-SEG and GSPS conversion

SETUP

The python package is available for use on PyPI. It can be setup simply via pip

pip install nekton

To the check the setup, simply check the version number of the nekton package by

python -c 'import nekton; print(nekton.__version__)'

DICOM to NifTi

The DICOM to NifTi conversion in the package is based on a wrapper around the dcm2niix software.

Usage

from nekton.dcm2nii import Dcm2Nii
converter = Dcm2Nii()
converted_files = converter.run(dicom_directory='/test_files/CT5N', name='Test')
# Converted 5 DCM to Nifti; Output stored @ /test_files/CT5N
print(converted_files)
# ['/test_files/CT5N/Test_SmartScore_-_Gated_0.5_sec_20010101000000_5.nii.gz']

Parameters converter.run:

  • dicom_directory (Path): path to directory with Dicoms
  • name (str, optional): Name to be given to the output file. Defaults to "".

Returns:

  • List[Path]: output list of Nifti files

Notes

  • The renaming functionality retains the suffixes from the original program.
  • The BIDS sidecar json is retained as well.

NifTi to DICOM-SEG

The NifTi to DICOM-SEG within nekton converts incoming segmentation NifTi to DICOM-SEG. The matching of the segmentation index to a text label is done via json file using the schema suggested by dcmqi. The json can be generated using the gui also an example can be seen here.

Currently, nekton supports creation of multiclass DICOM-SEG of two types-

  • single layer DICOM-SEG, where each non-empty slice has an individual file
  • multi layer DICOM-SEG, where all the n slices are rolled into a single file

Usage

  1. NifTi to single layer DICOM-SEG
from nekton.nii2dcm import Nii2DcmSeg
import glob
converter = Nii2DcmSeg()
path_dcms = [path for path in glob.glob(dir_dcms)]
path_mapping = "mapping.json"
path_seg_nifti = "CT5N_segmentation.nii.gz"
dcmsegs = converter_dcmseg.multiclass_converter(
        segfile = path_seg_nifti, segMapping= path_mapping, dcmfiles =path_dcms, multiLayer=False
    )
print (len(dcmsegs))
# 3
  1. NifTi to multi layer DICOM-SEG
from nekton.nii2dcm import Nii2DcmSeg
import glob
converter = Nii2DcmSeg()
path_dcms = [path for path in glob.glob(dir_dcms)]
path_mapping = "mapping.json"
path_seg_nifti = "CT5N_segmentation.nii.gz"
dcmsegs = converter.multiclass_converter(
        segfile = path_seg_nifti, segMapping= path_mapping, dcmfiles =path_dcms, multiLayer=True
    )
print (len(dcmsegs))
# 1

Parameters converter.multiclass_converter:

  • segfile (Path): path to the nifti segmentation file
  • segMapping (Path): path to the dcmqii format segmentation mapping json
  • dcmfiles (List[Path]): list of paths of all the source dicom files
  • multiLayer (bool, optional): create a single multilayer dicomseg. Defaults to False.

Returns:

  • List[Path]: list of paths of all generated dicomseg files

Notes

  • Multilabel NifTi(in the form of a NifTi file for a single label) to DICOM-SEG is under development.

NifTi to GSPS

This feature will be available in a future release of the nekton

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nekton-0.2.3.tar.gz (5.6 MB view details)

Uploaded Source

Built Distribution

nekton-0.2.3-py3-none-any.whl (5.7 MB view details)

Uploaded Python 3

File details

Details for the file nekton-0.2.3.tar.gz.

File metadata

  • Download URL: nekton-0.2.3.tar.gz
  • Upload date:
  • Size: 5.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for nekton-0.2.3.tar.gz
Algorithm Hash digest
SHA256 973714ca5679450cc182ecf5ecf8ed098cc73f350fdf7b1aef99823759dda03e
MD5 694ef341bd827cc97e97d070efa9f6ac
BLAKE2b-256 ea95602e0b79c7fe0cdb3a5d8c3f7cd87f1cf82c82460f12e8fb6eb2a8023631

See more details on using hashes here.

File details

Details for the file nekton-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: nekton-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for nekton-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c6cc65777f853f0438db36f3845da5fbbe83dd433017585aab6bd4bfc039acee
MD5 ba306f40b83662c1f27717c81fe35dbe
BLAKE2b-256 afa02ee235179b2a0a33ae0e65df5e61842ad216cd0ffc2a04e2dbd949e90664

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page