Tools for medical image processing with PyTorch
Pre-built datasets for common medical imaging research, including brain atlases, public medical imaging challenges, and synthetic datasets for testing and development. These datasets provide standardized access to well-known medical imaging data.
Standard brain templates and atlases commonly used in neuroimaging research for registration, normalization, and analysis.
class Colin27(Subject):
"""
Colin27 brain template.
Single-subject high-resolution T1-weighted brain template created from
27 scans of the same individual. Commonly used as reference for spatial
normalization and analysis.
"""
def __init__(self): ...
class ICBM2009CNonlinearSymmetric(Subject):
"""
ICBM 2009c nonlinear symmetric brain template.
Population-averaged brain template created from 152 T1-weighted images
of healthy adults. Part of the ICBM (International Consortium for Brain Mapping) initiative.
"""
def __init__(self): ...
class Pediatric(Subject):
"""
Pediatric brain template.
Age-appropriate brain template for pediatric neuroimaging studies,
representing typical brain anatomy in children.
"""
def __init__(self): ...
class Sheep(Subject):
"""
Sheep brain template.
Brain template for ovine (sheep) neuroimaging research,
useful for animal model studies and comparative neuroanatomy.
"""
def __init__(self): ...Usage example:
import torchio as tio
# Load brain templates
colin27 = tio.datasets.Colin27()
icbm_template = tio.datasets.ICBM2009CNonlinearSymmetric()
# Use as reference for registration
reference_space_transform = tio.ToReferenceSpace(target=colin27['t1'])
# Apply to other subjects
subject = tio.Subject(t1=tio.ScalarImage('patient_t1.nii.gz'))
registered = reference_space_transform(subject)Large-scale public datasets from medical imaging challenges and research initiatives, providing access to real clinical data for development and validation.
class IXI(SubjectsDataset):
"""
IXI dataset - brain MR images from healthy subjects.
Collection of brain MRI scans from nearly 600 healthy subjects,
including T1, T2, PD-weighted, MRA, and DTI images.
Parameters:
- root: Root directory for dataset storage
- download: Whether to download if not present
"""
def __init__(self, root: TypePath, download: bool = True): ...
class IXITiny(SubjectsDataset):
"""
Tiny version of IXI dataset for testing and development.
Small subset of IXI dataset with reduced data size,
ideal for quick testing and development workflows.
Parameters:
- root: Root directory for dataset storage
- download: Whether to download if not present
"""
def __init__(self, root: TypePath, download: bool = True): ...
class RSNAMICCAI(SubjectsDataset):
"""
RSNA-MICCAI Brain Tumor Radiogenomic Classification dataset.
Multimodal brain MRI scans with brain tumor segmentations and
genetic mutation predictions from RSNA-ASNR-MICCAI challenge.
Parameters:
- root: Root directory for dataset storage
- download: Whether to download if not present
"""
def __init__(self, root: TypePath, download: bool = True): ...
class RSNACervicalSpineFracture(SubjectsDataset):
"""
RSNA Cervical Spine Fracture dataset.
CT images of cervical spine with fracture annotations
from RSNA cervical spine fracture detection challenge.
Parameters:
- root: Root directory for dataset storage
- download: Whether to download if not present
"""
def __init__(self, root: TypePath, download: bool = True): ...
class EPISURG(SubjectsDataset):
"""
EPISURG dataset for epilepsy surgery planning.
Multimodal MRI dataset for epilepsy research including
T1, FLAIR, and other specialized sequences.
Parameters:
- root: Root directory for dataset storage
- download: Whether to download if not present
"""
def __init__(self, root: TypePath, download: bool = True): ...Sample datasets distributed with ITK-SNAP software, commonly used for teaching and demonstration purposes.
class BrainTumor(Subject):
"""
Brain tumor segmentation example from ITK-SNAP.
MRI brain scan with corresponding tumor segmentation,
commonly used for teaching medical image segmentation.
"""
def __init__(self): ...
class T1T2(Subject):
"""
T1 and T2 weighted brain MRI pair from ITK-SNAP.
Demonstrates multi-contrast brain imaging with
T1-weighted and T2-weighted MRI sequences.
"""
def __init__(self): ...
class AorticValve(Subject):
"""
Cardiac aortic valve imaging example from ITK-SNAP.
3D cardiac imaging data focused on aortic valve anatomy,
useful for cardiac image analysis applications.
"""
def __init__(self): ...3D versions of MedMNIST datasets, providing standardized benchmarks for 3D medical image analysis with classification and segmentation tasks.
class OrganMNIST3D(SubjectsDataset):
"""
3D organ segmentation dataset.
3D CT scans with multi-organ segmentation labels,
derived from the Medical Segmentation Decathlon.
Parameters:
- root: Root directory for dataset storage
- split: Dataset split ('train', 'val', 'test')
- download: Whether to download if not present
"""
def __init__(
self,
root: TypePath,
split: str = 'train',
download: bool = True
): ...
class NoduleMNIST3D(SubjectsDataset):
"""
3D lung nodule detection dataset.
3D chest CT scans with pulmonary nodule annotations
for nodule detection and classification tasks.
Parameters:
- root: Root directory for dataset storage
- split: Dataset split ('train', 'val', 'test')
- download: Whether to download if not present
"""
def __init__(
self,
root: TypePath,
split: str = 'train',
download: bool = True
): ...
class AdrenalMNIST3D(SubjectsDataset):
"""
3D adrenal gland segmentation dataset.
3D CT scans with adrenal gland segmentation labels
for endocrine system imaging applications.
"""
def __init__(
self,
root: TypePath,
split: str = 'train',
download: bool = True
): ...
class FractureMNIST3D(SubjectsDataset):
"""
3D fracture detection dataset.
3D CT scans with fracture annotations for
orthopedic imaging and trauma assessment.
"""
def __init__(
self,
root: TypePath,
split: str = 'train',
download: bool = True
): ...
class VesselMNIST3D(SubjectsDataset):
"""
3D blood vessel segmentation dataset.
3D imaging data with vascular structure segmentations
for cardiovascular and vascular imaging applications.
"""
def __init__(
self,
root: TypePath,
split: str = 'train',
download: bool = True
): ...
class SynapseMNIST3D(SubjectsDataset):
"""
3D synapse segmentation dataset.
3D electron microscopy data with synaptic structure
segmentations for neuroscience applications.
"""
def __init__(
self,
root: TypePath,
split: str = 'train',
download: bool = True
): ...class FPG(SubjectsDataset):
"""
Fernando Perez-Garcia research dataset.
Research dataset created by TorchIO's primary author,
useful for development and testing purposes.
Parameters:
- root: Root directory for dataset storage
- download: Whether to download if not present
"""
def __init__(self, root: TypePath, download: bool = True): ...
class Slicer(SubjectsDataset):
"""
3D Slicer sample data.
Sample medical imaging data distributed with 3D Slicer software,
covering various imaging modalities and anatomical regions.
Parameters:
- root: Root directory for dataset storage
- download: Whether to download if not present
"""
def __init__(self, root: TypePath, download: bool = True): ...
class BITE3(SubjectsDataset):
"""
BITE3 dataset for brain imaging.
Brain imaging dataset with specialized sequences
and annotations for neuroimaging research.
Parameters:
- root: Root directory for dataset storage
- download: Whether to download if not present
"""
def __init__(self, root: TypePath, download: bool = True): ...
class CtRate(SubjectsDataset):
"""
CT Rate dataset.
CT imaging dataset with rate-related annotations,
useful for temporal analysis and dynamic imaging studies.
Parameters:
- root: Root directory for dataset storage
- download: Whether to download if not present
"""
def __init__(self, root: TypePath, download: bool = True): ...Synthetic datasets for testing, development, and validation of image processing algorithms.
class ZonePlate(Subject):
"""
Synthetic zone plate for testing and development.
Mathematical zone plate pattern useful for testing
image processing algorithms, transforms, and visualization.
Parameters:
- shape: Image shape (default: (100, 100, 100))
- spacing: Voxel spacing (default: (1, 1, 1))
"""
def __init__(
self,
shape: tuple[int, int, int] = (100, 100, 100),
spacing: tuple[float, float, float] = (1, 1, 1)
): ...import torchio as tio
from pathlib import Path
# Download and load IXI dataset
data_dir = Path('./medical_data')
ixi_dataset = tio.datasets.IXI(root=data_dir, download=True)
print(f"IXI dataset contains {len(ixi_dataset)} subjects")
# Access individual subjects
subject = ixi_dataset[0]
print(f"Subject keys: {list(subject.keys())}")
# Use with transforms and data loaders
transforms = tio.Compose([
tio.ToCanonical(),
tio.Resample(2), # Downsample for faster processing
tio.ZNormalization(),
])
ixi_dataset.set_transform(transforms)
loader = tio.SubjectsLoader(ixi_dataset, batch_size=4, shuffle=True)
for batch in loader:
# Process batch of subjects
pass# Load standard brain template
colin27 = tio.datasets.Colin27()
# Use as reference for spatial normalization
def create_normalization_pipeline(reference_template):
return tio.Compose([
tio.ToCanonical(),
tio.ToReferenceSpace(target=reference_template['t1']),
tio.ZNormalization(),
])
normalization = create_normalization_pipeline(colin27)
# Apply to patient data
patient = tio.Subject(t1=tio.ScalarImage('patient_brain.nii.gz'))
normalized = normalization(patient)# Load 3D medical classification dataset
organ_train = tio.datasets.OrganMNIST3D(
root='./medmnist_data',
split='train',
download=True
)
organ_val = tio.datasets.OrganMNIST3D(
root='./medmnist_data',
split='val',
download=False
)
# Create augmentation for training
train_transform = tio.Compose([
tio.RandomFlip(),
tio.RandomAffine(degrees=(-5, 5)),
tio.RandomNoise(std=(0, 0.05)),
])
# Apply transforms
organ_train.set_transform(train_transform)
# Use for model training
train_loader = tio.SubjectsLoader(
organ_train,
batch_size=16,
shuffle=True,
num_workers=4
)
for batch in train_loader:
images = batch['image'][tio.DATA]
labels = batch['label'][tio.DATA]
# Train model# Create synthetic test data
zone_plate = tio.datasets.ZonePlate(
shape=(64, 64, 64),
spacing=(1, 1, 1)
)
# Test transforms on synthetic data
test_transforms = tio.Compose([
tio.RandomAffine(degrees=(-10, 10)),
tio.RandomElasticDeformation(),
tio.RandomNoise(std=0.1),
])
augmented_zone_plate = test_transforms(zone_plate)
# Verify transform behavior
print(f"Original shape: {zone_plate.shape}")
print(f"Augmented shape: {augmented_zone_plate.shape}")Install with Tessl CLI
npx tessl i tessl/pypi-torchio