[work] — Monai Data Augmentation
| Transform | Description | |-----------|-------------| | RandCropByPosNegLabel | Crop based on presence of foreground/background | | RandSpatialCrop | Random crop preserving spatial context | | RandWeightedCrop | Crop with probability map | | Transform | Description | |-----------|-------------| | RandCoarseShuffle | Randomly shuffle patches across channels (simulate missing modality) | | RandChannelShuffle | Shuffle MRI sequences (T1, T2, FLAIR) | 4. Practical Implementation 4.1 Basic Augmentation Pipeline for 3D Segmentation import monai from monai.transforms import ( Compose, RandRotate, RandZoom, RandGaussianNoise, RandFlip, RandAffine, EnsureChannelFirst, ScaleIntensity ) train_transforms = Compose([ EnsureChannelFirst(), # (H,W,D) -> (C,H,W,D) ScaleIntensity(), # Normalize to [0,1] RandRotate(range_x=0.2, range_y=0.2, range_z=0.1, prob=0.5), RandZoom(min_zoom=0.9, max_zoom=1.1, prob=0.3), RandGaussianNoise(std=0.05, prob=0.4), RandFlip(spatial_axis=0, prob=0.5), RandAffine(translate_range=10, rotate_range=0.1, scale_range=0.1), ]) Apply to image and label using RandAffined for paired transforms paired_transforms = monai.transforms.Compose([ monai.transforms.LoadImaged(keys=["image", "label"]), monai.transforms.EnsureChannelFirstd(keys=["image", "label"]), monai.transforms.ScaleIntensityd(keys=["image"]), monai.transforms.RandRotated(keys=["image", "label"], prob=0.5, range_x=0.2), monai.transforms.RandZoomd(keys=["image", "label"], prob=0.3, min_zoom=0.9, max_zoom=1.1), ]) 4.2 GPU-Accelerated Dictionary Transforms Use *d transforms for dictionary-based datasets (recommended for large 3D data):
1. Introduction MONAI (Medical Open Network for AI) is an open-source framework built on PyTorch for deep learning in medical imaging. A critical component of training robust models is data augmentation – transforming training data to increase diversity, reduce overfitting, and improve generalization. MONAI provides a rich, domain-specific augmentation library designed for medical images (3D, multi-modal, high-resolution) with GPU acceleration and composable transforms. 2. Why MONAI for Medical Image Augmentation? | Feature | Benefit | |---------|---------| | Medical domain awareness | Preserves spatial relationships, handles missing modalities, supports metadata (e.g., pixel spacing) | | 3D & multi-channel support | Native handling of CT, MRI, PET volumes and multi-sequence MRI | | GPU-accelerated | Transforms run on GPU via PyTorch’s grid_sample and affine_grid | | Composable pipelines | Compose , RandomOrder , OneOf for flexible augmentation sequences | | Randomized & deterministic | Reproducible training with seed control | | Integration with MONAI workflows | Works seamlessly with Dataset , CacheDataset , DataLoader | 3. Core Augmentation Categories 3.1 Intensity Augmentations Modify pixel/voxel values to simulate acquisition variability. monai data augmentation
from monai.transforms import ( RandGaussianNoised, RandAffined, RandGridDistortiond, RandAdjustContrastd ) augmentation = RandAffined( keys=["image", "label"], prob=0.5, rotate_range=(0.2, 0.2, 0.1), translate_range=(10, 10, 5), scale_range=(0.9, 1.1), mode=("bilinear", "nearest"), # Different interpolation for image vs label padding_mode="border" ) from monai.transforms import RandRotate, RandZoom, RandGaussianNoise, OneOf, RandomOrder advanced_aug = RandomOrder([ RandRotate(range_x=0.2, prob=0.8), RandZoom(prob=0.6), OneOf([ RandGaussianNoise(prob=1.0), monai.transforms.RandAdjustContrast(prob=1.0), ]) ]) 5. Performance Considerations | Aspect | Recommendation | |--------|----------------| | Batch augmentation | Use Rand* transforms inside DataLoader with num_workers>0 | | CacheDataset | Apply deterministic transforms before caching; random after caching | | CPU vs GPU | For large 3D volumes, GPU transforms are 5-10x faster | | Memory | Avoid heavy random grids stored per sample – MONAI generates on-the-fly | 6. Example: Full Training Pipeline with MONAI Augmentation from monai.data import CacheDataset, DataLoader from monai.transforms import Compose, LoadImaged, RandRotated, RandZoomd Define transforms train_transform = Compose([ LoadImaged(keys=["image", "label"]), EnsureChannelFirstd(keys=["image", "label"]), ScaleIntensityRanged(keys=["image"], a_min=-1000, a_max=1000), RandRotated(keys=["image", "label"], prob=0.5, range_x=0.3), RandZoomd(keys=["image", "label"], prob=0.3, min_zoom=0.8, max_zoom=1.2), RandGaussianNoised(keys=["image"], prob=0.4, std=0.05), ToTensord(keys=["image", "label"]) ]) Dataset & loader dataset = CacheDataset(data=data_list, transform=train_transform, cache_rate=1.0) loader = DataLoader(dataset, batch_size=4, shuffle=True, num_workers=4) A critical component of training robust models is




