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/runner/.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%|          | 229376/58169474 [00:00<00:25, 2281063.33it/s]
  6%|▌         | 3284992/58169474 [00:00<00:02, 18863889.33it/s]
 18%|█▊        | 10706944/58169474 [00:00<00:01, 44086518.27it/s]
 28%|██▊       | 16400384/58169474 [00:00<00:00, 49151159.17it/s]
 40%|███▉      | 23191552/58169474 [00:00<00:00, 55895968.63it/s]
 51%|█████     | 29532160/58169474 [00:00<00:00, 58427769.54it/s]
 61%|██████    | 35282944/58169474 [00:00<00:00, 58126206.21it/s]
 72%|███████▏  | 41656320/58169474 [00:00<00:00, 59905500.61it/s]
 82%|████████▏ | 47546368/58169474 [00:01<00:00, 58617426.68it/s]
 92%|█████████▏| 53346304/58169474 [00:01<00:00, 57668073.88it/s]
58171392it [00:01, 45894920.16it/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 19.041 seconds)

Gallery generated by Sphinx-Gallery