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%|          | 16384/58169474 [00:00<07:11, 134912.85it/s]
  1%|          | 417792/58169474 [00:00<00:27, 2068460.95it/s]
  5%|5         | 3072000/58169474 [00:00<00:04, 12263311.68it/s]
 12%|#1        | 6864896/58169474 [00:00<00:02, 21806960.99it/s]
 19%|#9        | 11173888/58169474 [00:00<00:01, 29061826.01it/s]
 26%|##5       | 14966784/58169474 [00:00<00:01, 31910519.82it/s]
 33%|###3      | 19210240/58169474 [00:00<00:01, 35245338.95it/s]
 40%|###9      | 23068672/58169474 [00:00<00:00, 36172792.11it/s]
 47%|####6     | 27312128/58169474 [00:00<00:00, 38008926.59it/s]
 54%|#####3    | 31170560/58169474 [00:01<00:00, 38054891.47it/s]
 61%|######    | 35414016/58169474 [00:01<00:00, 39249968.21it/s]
 68%|######7   | 39354368/58169474 [00:01<00:00, 39099773.66it/s]
 75%|#######4  | 43515904/58169474 [00:01<00:00, 39819275.35it/s]
 82%|########1 | 47505408/58169474 [00:01<00:00, 39421121.91it/s]
 89%|########8 | 51683328/58169474 [00:01<00:00, 39816723.47it/s]
 96%|#########5| 55697408/58169474 [00:01<00:00, 39911403.70it/s]
58171392it [00:01, 33999878.79it/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.599 seconds)

Gallery generated by Sphinx-Gallery