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), t1 (coronal), t1 (axial), t2 (sagittal), t2 (coronal), t2 (axial), pd (sagittal), pd (coronal), pd (axial), mask (sagittal), mask (coronal), mask (axial)
  • t1 (sagittal), t1 (coronal), t1 (axial), t2 (sagittal), t2 (coronal), t2 (axial), pd (sagittal), pd (coronal), pd (axial), mask (sagittal), mask (coronal), 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%|          | 147456/58169474 [00:00<00:43, 1326269.53it/s]
  3%|2         | 1744896/58169474 [00:00<00:05, 9534434.96it/s]
 10%|#         | 6037504/58169474 [00:00<00:02, 24105191.68it/s]
 19%|#8        | 10903552/58169474 [00:00<00:01, 33563211.76it/s]
 27%|##7       | 15933440/58169474 [00:00<00:01, 39445337.19it/s]
 36%|###6      | 21012480/58169474 [00:00<00:00, 43234241.96it/s]
 45%|####4     | 26165248/58169474 [00:00<00:00, 45921825.56it/s]
 54%|#####3    | 31309824/58169474 [00:00<00:00, 47666892.76it/s]
 62%|######2   | 36347904/58169474 [00:01<00:00, 48502863.59it/s]
 71%|#######   | 41205760/58169474 [00:01<00:00, 48477219.55it/s]
 79%|#######9  | 46063616/58169474 [00:01<00:00, 48490417.20it/s]
 88%|########8 | 51240960/58169474 [00:01<00:00, 49486489.93it/s]
 97%|#########7| 56483840/58169474 [00:01<00:00, 50368404.63it/s]
58171392it [00:09, 6434129.15it/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.130 seconds)

Gallery generated by Sphinx-Gallery