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%| | 204800/58169474 [00:00<00:31, 1849278.28it/s]
6%|▌ | 3276800/58169474 [00:00<00:03, 17032426.95it/s]
16%|█▋ | 9486336/58169474 [00:00<00:01, 36439412.47it/s]
26%|██▌ | 15253504/58169474 [00:00<00:00, 44362975.93it/s]
37%|███▋ | 21487616/58169474 [00:00<00:00, 50281927.48it/s]
48%|████▊ | 28114944/58169474 [00:00<00:00, 55480482.46it/s]
58%|█████▊ | 33964032/58169474 [00:00<00:00, 56447953.77it/s]
70%|███████ | 40845312/58169474 [00:01<00:00, 59856566.57it/s]
82%|████████▏ | 47423488/58169474 [00:01<00:00, 61679761.83it/s]
93%|█████████▎| 54149120/58169474 [00:01<00:00, 63255057.73it/s]
58171392it [00:01, 40982728.52it/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 21.622 seconds)