Note
Go to the end to download the full example code.
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.
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%| | 212992/58169474 [00:00<00:28, 2009947.21it/s]
3%|▎ | 1744896/58169474 [00:00<00:07, 7552268.70it/s]
18%|█▊ | 10584064/58169474 [00:00<00:01, 39145205.12it/s]
35%|███▍ | 20299776/58169474 [00:00<00:00, 59790760.94it/s]
48%|████▊ | 27934720/58169474 [00:00<00:00, 57838840.83it/s]
66%|██████▌ | 38191104/58169474 [00:00<00:00, 60797014.57it/s]
84%|████████▍ | 48807936/58169474 [00:00<00:00, 69838362.73it/s]
58171392it [00:01, 54573888.06it/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 9.930 seconds)