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:32, 1786670.09it/s]
  4%|▍         | 2482176/58169474 [00:00<00:04, 13307790.71it/s]
 14%|█▎        | 7888896/58169474 [00:00<00:01, 31169555.49it/s]
 23%|██▎       | 13213696/58169474 [00:00<00:01, 39500620.76it/s]
 33%|███▎      | 19193856/58169474 [00:00<00:00, 46154577.55it/s]
 42%|████▏     | 24657920/58169474 [00:00<00:00, 48498510.99it/s]
 53%|█████▎    | 30638080/58169474 [00:00<00:00, 52100369.81it/s]
 63%|██████▎   | 36429824/58169474 [00:00<00:00, 50066740.14it/s]
 72%|███████▏  | 41664512/58169474 [00:01<00:00, 50735647.12it/s]
 83%|████████▎ | 48193536/58169474 [00:01<00:00, 54560244.18it/s]
 94%|█████████▍| 54624256/58169474 [00:01<00:00, 57073923.78it/s]
58171392it [00:01, 41855899.50it/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.069 seconds)

Gallery generated by Sphinx-Gallery