Monai Data Augmentation – Tested & Working
| 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):
| Transform | Description | Example Use Case | |-----------|-------------|------------------| | RandGaussianNoise | Add Gaussian noise | Low-dose CT | | RandGaussianSmooth | Smooth with Gaussian kernel | Different scanner resolutions | | RandAdjustContrast | Random contrast adjustment | Varying soft tissue contrast | | RandHistogramShift | Random shift in histogram | MRI field inhomogeneity | | RandBiasField | Simulate MRI bias field | Brain MRI intensity non-uniformity | | RandGibbsNoise | Truncation artifact | Under-sampled MRI | | RandCoarseDropout | Simulate missing patches | Occlusions, motion artifacts | Modify geometry while preserving anatomical plausibility. monai data augmentation
| Transform | Description | Medical Relevance | |-----------|-------------|-------------------| | RandFlip | Random axis flip (left-right, etc.) | Mirror anatomy | | RandRotate | Random rotation (limited degrees) | Patient positioning | | RandZoom | Random scaling | Different patient sizes | | RandAffine | Combined affine (rotation, scale, shear, translation) | Complex deformations | | RandGridDistortion | Local elastic deformation | Organ motion, breathing | | Rand2DElastic | 2D elastic (for slices) | Tissue deformation | | Transform | Description | |-----------|-------------| | RandSimulateLowResolution | Reduce effective resolution | | RandSpacing | Randomly change pixel spacing (simulate different acquisition grids) | 3.4 Mask & Label Augmentations For segmentation tasks – transforms applied consistently to image and mask. # Normalize to [0