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)

Out:

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, 1836413.56it/s]
  4%|3         | 2236416/58169474 [00:00<00:04, 12210247.76it/s]
 11%|#1        | 6529024/58169474 [00:00<00:01, 25876463.58it/s]
 20%|##        | 11845632/58169474 [00:00<00:01, 36430327.56it/s]
 30%|##9       | 17309696/58169474 [00:00<00:00, 42859568.20it/s]
 39%|###9      | 22970368/58169474 [00:00<00:00, 47373598.39it/s]
 49%|####8     | 28434432/58169474 [00:00<00:00, 49722692.96it/s]
 58%|#####8    | 33964032/58169474 [00:00<00:00, 51464689.20it/s]
 68%|######7   | 39493632/58169474 [00:01<00:00, 52593536.53it/s]
 77%|#######7  | 44990464/58169474 [00:01<00:00, 53320775.25it/s]
 87%|########7 | 50618368/58169474 [00:01<00:00, 54017007.72it/s]
 96%|#########6| 56082432/58169474 [00:01<00:00, 54139993.83it/s]
58171392it [00:01, 41559088.08it/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.166 seconds)

Gallery generated by Sphinx-Gallery