Exclude images from transform#

In this example we show how the kwargs include and exclude can be used to apply a transform to only some of the images within a subject.

  • t1 (sagittal), t2 (sagittal), pd (sagittal), mask (sagittal), t1 (coronal), t2 (coronal), pd (coronal), mask (coronal), t1 (axial), t2 (axial), pd (axial), mask (axial)
  • t1 (sagittal), t2 (sagittal), pd (sagittal), mask (sagittal), t1 (coronal), t2 (coronal), pd (coronal), mask (coronal), t1 (axial), t2 (axial), pd (axial), mask (axial)
Downloading http://www.bic.mni.mcgill.ca/~vfonov/nihpd/obj1/nihpd_asym_04.5-08.5_nifti.zip to /home/docs/.cache/torchio/nihpd_asym_04.5-08.5_nifti/nihpd_asym_04.5-08.5_nifti.zip

0it [00:00, ?it/s]
  0%|          | 0/58169474 [00:00<?, ?it/s]
  0%|          | 204800/58169474 [00:00<00:31, 1859252.96it/s]
  4%|4         | 2351104/58169474 [00:00<00:04, 12916169.88it/s]
 13%|#2        | 7503872/58169474 [00:00<00:01, 30144985.74it/s]
 23%|##3       | 13549568/58169474 [00:00<00:01, 41811851.71it/s]
 35%|###5      | 20430848/58169474 [00:00<00:00, 51329067.89it/s]
 48%|####8     | 27959296/58169474 [00:00<00:00, 59254570.27it/s]
 62%|######2   | 36249600/58169474 [00:00<00:00, 66786074.34it/s]
 77%|#######7  | 44990464/58169474 [00:01<00:00, 73215274.25it/s]
 93%|#########3| 54288384/58169474 [00:01<00:00, 79358828.11it/s]
58171392it [00:01, 49980468.22it/s]

import torch
import torchio as tio


torch.manual_seed(0)

subject = tio.datasets.Pediatric(years=(4.5, 8.5))
subject.plot()
transform = tio.Compose([
    tio.RandomAffine(degrees=(20, 30), exclude='t1'),
    tio.RandomBlur(std=(3, 4), include='t2'),
])
transformed = transform(subject)
transformed.plot()

Total running time of the script: ( 0 minutes 13.556 seconds)

Gallery generated by Sphinx-Gallery