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%| | 114688/58169474 [00:00<03:20, 290160.58it/s]
1%| | 614400/58169474 [00:01<00:38, 1509254.09it/s]
2%|▏ | 1220608/58169474 [00:01<00:21, 2688924.74it/s]
3%|▎ | 1957888/58169474 [00:01<00:14, 3896739.59it/s]
5%|▍ | 2850816/58169474 [00:01<00:10, 5188667.11it/s]
7%|▋ | 3932160/58169474 [00:01<00:08, 6626122.61it/s]
9%|▉ | 5242880/58169474 [00:01<00:06, 8266121.10it/s]
12%|█▏ | 6823936/58169474 [00:01<00:05, 10187306.59it/s]
15%|█▍ | 8626176/58169474 [00:01<00:03, 12401569.83it/s]
18%|█▊ | 10592256/58169474 [00:01<00:03, 14447167.58it/s]
23%|██▎ | 13197312/58169474 [00:02<00:02, 17786933.80it/s]
28%|██▊ | 16293888/58169474 [00:02<00:01, 21648870.53it/s]
34%|███▎ | 19546112/58169474 [00:02<00:01, 24844556.75it/s]
41%|████ | 23969792/58169474 [00:02<00:01, 30591929.30it/s]
50%|████▉ | 28917760/58169474 [00:02<00:00, 36097734.48it/s]
60%|█████▉ | 34717696/58169474 [00:02<00:00, 42606308.14it/s]
70%|███████ | 40878080/58169474 [00:02<00:00, 48069215.29it/s]
83%|████████▎ | 48381952/58169474 [00:02<00:00, 56102046.19it/s]
96%|█████████▌| 55795712/58169474 [00:02<00:00, 61383152.31it/s]
58171392it [00:02, 20328685.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 16.239 seconds)