Skip to main content

Convert3D family of tools from the Penn Image Computing and Science Lab (PICSL)

Project description

Python wrappers for PICSL Convert3D Tools

This project provides a Python interface for the Convert3D tool from the Penn Image Computing and Science Laboratory, developers of ITK-SNAP.

Convert3D is a format conversion and multi-functional processing tool for 3D (also 2D and 4D) medical images. Complex pipelines can be created by putting commands on Convert3D command line in the correct order. Please see Convert3D Reference for complete documentation.

This project makes it possible to interface with Convert3D from Python code. You can execute pipelines as you would on the command line, and you access images on the Convert3D stack as SimpleITK image objects.

Quick Start

Install the package:

pip install picsl_c3d

Download an image to play with (optional of course)

curl -L http://www.nitrc.org/frs/download.php/750/MRI-crop.zip -o MRI-crop.zip
unzip MRI-crop.zip

Do some processing in Python

from picsl_c3d import Convert3D

c = Convert3D()

c.execute('MRIcrop-orig.gipl MRIcrop-seg.gipl -lstat')

SimpleITK Interface

You can read/write images from disk using the command line options passed to the execute command. But if you want to mix Python-based image processing pipelines and Convert3D pipelines, using the disk to store images creates unnecessary overhead. For the users of SimpleITK, additional commands are available to add images to the Convert3D stack and to read images from the stack.

from picsl_c3d import Convert3D
import SimpleITK as sitk

c = Convert3D()

img = sitk.ReadImage('MRIcrop-orig.gipl')       # Load image with SimpleITK
c.push(img)                                     # Put image on the stack
c.execute('-smooth 1vox -resample 50% -slice z 50%')  # Make a thumbnail
img_slice = c.peek(-1)                          # Get the last image on the stack

Capturing and Parsing Text Output

Sometimes you want to capture parts of the output from a Convert3D. This example redirects the output of the execute command to a StringIO buffer, and then uses regular expressions to parse out a piece of information that we want:

from picsl_c3d import Convert3D
import io
import re
import numpy as np

c = Convert3D()
s = io.StringIO()                         # Create an output stream

# Run c3d "pipeline" capturing output
img='MRIcrop-orig.gipl'
c.execute(f'{img} -probe 50%', out=s)     # Run command, capturing output to s
print(f'c3d output: {s.getvalue()}')      # Print the output of the command, returns
                                          # 'Interpolated image value at -39 -55 32 is 21'

# Parse the c3d output
line = s.getvalue().split('\n')[0]        # Take first line from output
matches = re.split('( at | is )', line)   # Split the line on words "at" and "is"
pos = np.fromstring(matches[2], sep=' ')  # Store the position -39 -55 32 as Numpy array
val = float(matches[4])                   # Store the intensity 21

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

picsl_c3d-1.4.2.2-pp310-pypy310_pp73-win_amd64.whl (6.0 MB view hashes)

Uploaded PyPy Windows x86-64

picsl_c3d-1.4.2.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

picsl_c3d-1.4.2.2-pp310-pypy310_pp73-macosx_11_0_arm64.whl (10.1 MB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

picsl_c3d-1.4.2.2-pp310-pypy310_pp73-macosx_10_15_x86_64.whl (12.0 MB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

picsl_c3d-1.4.2.2-pp39-pypy39_pp73-win_amd64.whl (6.0 MB view hashes)

Uploaded PyPy Windows x86-64

picsl_c3d-1.4.2.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

picsl_c3d-1.4.2.2-pp39-pypy39_pp73-macosx_11_0_arm64.whl (10.1 MB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

picsl_c3d-1.4.2.2-pp39-pypy39_pp73-macosx_10_15_x86_64.whl (12.0 MB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

picsl_c3d-1.4.2.2-pp38-pypy38_pp73-win_amd64.whl (6.0 MB view hashes)

Uploaded PyPy Windows x86-64

picsl_c3d-1.4.2.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

picsl_c3d-1.4.2.2-pp38-pypy38_pp73-macosx_11_0_arm64.whl (10.1 MB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

picsl_c3d-1.4.2.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

picsl_c3d-1.4.2.2-cp313-cp313-win_amd64.whl (6.0 MB view hashes)

Uploaded CPython 3.13 Windows x86-64

picsl_c3d-1.4.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

picsl_c3d-1.4.2.2-cp313-cp313-macosx_11_0_arm64.whl (10.1 MB view hashes)

Uploaded CPython 3.13 macOS 11.0+ ARM64

picsl_c3d-1.4.2.2-cp313-cp313-macosx_10_13_x86_64.whl (12.0 MB view hashes)

Uploaded CPython 3.13 macOS 10.13+ x86-64

picsl_c3d-1.4.2.2-cp312-cp312-win_amd64.whl (6.0 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

picsl_c3d-1.4.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

picsl_c3d-1.4.2.2-cp312-cp312-macosx_11_0_arm64.whl (10.1 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

picsl_c3d-1.4.2.2-cp312-cp312-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

picsl_c3d-1.4.2.2-cp311-cp311-win_amd64.whl (6.0 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

picsl_c3d-1.4.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

picsl_c3d-1.4.2.2-cp311-cp311-macosx_11_0_arm64.whl (10.1 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

picsl_c3d-1.4.2.2-cp311-cp311-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

picsl_c3d-1.4.2.2-cp310-cp310-win_amd64.whl (6.0 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

picsl_c3d-1.4.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

picsl_c3d-1.4.2.2-cp310-cp310-macosx_11_0_arm64.whl (10.1 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

picsl_c3d-1.4.2.2-cp310-cp310-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

picsl_c3d-1.4.2.2-cp39-cp39-win_amd64.whl (6.0 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

picsl_c3d-1.4.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

picsl_c3d-1.4.2.2-cp39-cp39-macosx_11_0_arm64.whl (10.1 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

picsl_c3d-1.4.2.2-cp39-cp39-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

picsl_c3d-1.4.2.2-cp38-cp38-win_amd64.whl (6.0 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

picsl_c3d-1.4.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

picsl_c3d-1.4.2.2-cp38-cp38-macosx_11_0_arm64.whl (10.1 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

picsl_c3d-1.4.2.2-cp38-cp38-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

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