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%|          | 40960/58169474 [00:00<02:44, 352402.51it/s]
  1%|1         | 819200/58169474 [00:00<00:13, 4192896.34it/s]
  8%|7         | 4636672/58169474 [00:00<00:02, 18667511.80it/s]
 17%|#6        | 9732096/58169474 [00:00<00:01, 30688351.85it/s]
 26%|##6       | 15368192/58169474 [00:00<00:01, 39653583.69it/s]
 39%|###8      | 22437888/58169474 [00:00<00:00, 49983608.54it/s]
 51%|#####1    | 29794304/58169474 [00:00<00:00, 57329330.60it/s]
 66%|######5   | 38330368/58169474 [00:00<00:00, 66123438.99it/s]
 81%|########  | 46972928/58169474 [00:00<00:00, 72392360.96it/s]
 98%|#########8| 57196544/58169474 [00:01<00:00, 81544676.40it/s]
58171392it [00:01, 55776347.83it/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 18.678 seconds)

Gallery generated by Sphinx-Gallery