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%|          | 122880/58169474 [00:00<00:52, 1106522.55it/s]
  4%|▎         | 2105344/58169474 [00:00<00:05, 11118117.44it/s]
 14%|█▍        | 8282112/58169474 [00:00<00:01, 32890907.98it/s]
 24%|██▎       | 13746176/58169474 [00:00<00:01, 40750121.03it/s]
 35%|███▍      | 20316160/58169474 [00:00<00:00, 49338980.39it/s]
 46%|████▋     | 26927104/58169474 [00:00<00:00, 54860259.52it/s]
 58%|█████▊    | 33677312/58169474 [00:00<00:00, 58599950.61it/s]
 71%|███████   | 41197568/58169474 [00:00<00:00, 63749662.63it/s]
 83%|████████▎ | 48340992/58169474 [00:01<00:00, 66126473.61it/s]
 96%|█████████▋| 55992320/58169474 [00:01<00:00, 69048513.84it/s]
58171392it [00:01, 47820441.88it/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 14.261 seconds)

Gallery generated by Sphinx-Gallery