Note
Click here 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, 1829966.21it/s]
4%|3 | 2244608/58169474 [00:00<00:04, 12233565.51it/s]
13%|#3 | 7610368/58169474 [00:00<00:01, 30642359.71it/s]
23%|##3 | 13492224/58169474 [00:00<00:01, 41582815.79it/s]
35%|###4 | 20299776/58169474 [00:00<00:00, 51029306.88it/s]
48%|####8 | 28049408/58169474 [00:01<00:00, 59922547.78it/s]
64%|######3 | 37085184/58169474 [00:01<00:00, 69809405.82it/s]
81%|########1 | 47226880/58169474 [00:01<00:00, 79667861.05it/s]
99%|#########8| 57442304/58169474 [00:01<00:00, 86665227.41it/s]
58171392it [00:01, 41909893.29it/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 14.202 seconds)