Command-line interface
TorchIO includes a torchio command with several subcommands.
Usage
Pass --version to print the installed TorchIO version and exit.
Reference
The CLI is built with tyro. Help text for each subcommand is generated from the source code.
Plot
dataclass
Plot 3 orthogonal slices of an image.
Source code in src/torchio/cli.py
path
instance-attribute
Path to the image file.
channel = 0
class-attribute
instance-attribute
Channel index to display.
output = None
class-attribute
instance-attribute
Save the figure to a file instead of displaying.
indices = None
class-attribute
instance-attribute
Slice indices (i, j, k). Defaults to mid-slices.
Animate
dataclass
Create an animated GIF or MP4 sweeping through slices.
The output format is inferred from the file extension:
.gif produces an animated GIF, .mp4 produces a video.
Examples::
torchio animate brain.nii.gz brain.gif
torchio animate brain.nii.gz brain.mp4 --seconds 10 --direction S
Source code in src/torchio/cli.py
path
instance-attribute
Path to the input image.
output
instance-attribute
Output path (.gif or .mp4).
seconds = 5.0
class-attribute
instance-attribute
Duration of the animation in seconds.
direction = 'I'
class-attribute
instance-attribute
Anatomical sweep direction (I, S, A, P, R, or L).
Info
dataclass
Print image metadata to stdout.
Source code in src/torchio/cli.py
path
instance-attribute
Path to the image file.
Convert
dataclass
Convert an image between formats.
Supports all SimpleITK formats plus NIfTI-Zarr (.nii.zarr). The output format is inferred from the file extension.
Source code in src/torchio/cli.py
input
instance-attribute
Path to the input image.
output
instance-attribute
Path for the output image.
Transform
dataclass
Apply a transform to an image.
Extra arguments are passed as key=value pairs to the transform.
Examples::
torchio transform brain.nii.gz noisy.nii.gz Noise std=0.1
torchio transform brain.nii.gz cropped.nii.gz CropOrPad target_shape=128
Source code in src/torchio/cli.py
input
instance-attribute
Path to the input image.
output
instance-attribute
Path for the output image.
name
instance-attribute
Transform class name (e.g., Noise, Flip, CropOrPad).
device = 'cpu'
class-attribute
instance-attribute
Device to run the transform on (e.g., "cpu", "cuda", "cuda:0" or "mps").
args = field(default_factory=list)
class-attribute
instance-attribute
Extra arguments as key=value pairs (e.g., std=0.1).
Cache
dataclass
Dir
dataclass
Clean
dataclass
Clear cached data.
Source code in src/torchio/cli.py
dataset = None
class-attribute
instance-attribute
Dataset name to clear (e.g., 'colin27', 'fpg'). Clears all if omitted.