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), t2 (sagittal), pd (sagittal), mask (sagittal), t1 (coronal), t2 (coronal), pd (coronal), mask (coronal), t1 (axial), t2 (axial), pd (axial), mask (axial)
  • t1 (sagittal), t2 (sagittal), pd (sagittal), mask (sagittal), t1 (coronal), t2 (coronal), pd (coronal), mask (coronal), t1 (axial), t2 (axial), pd (axial), mask (axial)
Downloading http://www.bic.mni.mcgill.ca/~vfonov/nihpd/obj1/nihpd_asym_04.5-08.5_nifti.zip to /home/user/.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:02<?, ?it/s]
  0%|          | 16384/58169474 [00:02<06:31, 148709.34it/s]
  0%|          | 40960/58169474 [00:02<05:01, 192529.97it/s]
  0%|          | 90112/58169474 [00:02<03:07, 310132.07it/s]
  0%|          | 188416/58169474 [00:02<01:48, 535157.88it/s]
  1%|          | 360448/58169474 [00:02<01:02, 923119.66it/s]
  1%|          | 704512/58169474 [00:02<00:34, 1684465.66it/s]
  2%|▏         | 1368064/58169474 [00:02<00:17, 3207011.69it/s]
  3%|▎         | 1982464/58169474 [00:02<00:13, 4086666.22it/s]
  4%|▍         | 2605056/58169474 [00:03<00:19, 2899526.39it/s]
  5%|▌         | 3031040/58169474 [00:03<00:20, 2713964.14it/s]
 10%|▉         | 5750784/58169474 [00:03<00:07, 7338757.18it/s]
 11%|█▏        | 6643712/58169474 [00:03<00:07, 6793533.32it/s]
 13%|█▎        | 7430144/58169474 [00:03<00:07, 6467467.77it/s]
 14%|█▍        | 8151040/58169474 [00:04<00:07, 6331994.82it/s]
 15%|█▌        | 8839168/58169474 [00:04<00:08, 6137622.37it/s]
 16%|█▋        | 9543680/58169474 [00:04<00:07, 6346482.69it/s]
 18%|█▊        | 10207232/58169474 [00:04<00:08, 5985268.66it/s]
 19%|█▊        | 10829824/58169474 [00:04<00:08, 5882866.44it/s]
 20%|█▉        | 11526144/58169474 [00:04<00:07, 6066498.90it/s]
 21%|██        | 12148736/58169474 [00:04<00:07, 5986706.73it/s]
 22%|██▏       | 12754944/58169474 [00:04<00:07, 5965603.83it/s]
 23%|██▎       | 13426688/58169474 [00:04<00:07, 6117552.18it/s]
 24%|██▍       | 14073856/58169474 [00:05<00:07, 6217185.64it/s]
 25%|██▌       | 14737408/58169474 [00:05<00:06, 6313096.96it/s]
 27%|██▋       | 15425536/58169474 [00:05<00:06, 6477767.30it/s]
 28%|██▊       | 16080896/58169474 [00:05<00:06, 6464184.86it/s]
 29%|██▉       | 16760832/58169474 [00:05<00:06, 6497712.86it/s]
 30%|██▉       | 17440768/58169474 [00:05<00:06, 6580261.07it/s]
 31%|███       | 18104320/58169474 [00:05<00:06, 6580744.96it/s]
 32%|███▏      | 18776064/58169474 [00:05<00:05, 6613237.85it/s]
 33%|███▎      | 19456000/58169474 [00:05<00:05, 6649001.88it/s]
 35%|███▍      | 20144128/58169474 [00:05<00:05, 6714028.94it/s]
 36%|███▌      | 20815872/58169474 [00:06<00:05, 6703463.00it/s]
 37%|███▋      | 21487616/58169474 [00:06<00:05, 6696286.29it/s]
 38%|███▊      | 22159360/58169474 [00:06<00:05, 6679072.87it/s]
 39%|███▉      | 22847488/58169474 [00:06<00:05, 6731675.05it/s]
 41%|████      | 23560192/58169474 [00:06<00:05, 6836435.08it/s]
 42%|████▏     | 24248320/58169474 [00:06<00:05, 6472333.32it/s]
 43%|████▎     | 24985600/58169474 [00:06<00:04, 6649474.39it/s]
 44%|████▍     | 25657344/58169474 [00:06<00:04, 6537592.50it/s]
 45%|████▌     | 26329088/58169474 [00:06<00:04, 6544758.44it/s]
 47%|████▋     | 27058176/58169474 [00:06<00:04, 6758993.81it/s]
 48%|████▊     | 27738112/58169474 [00:07<00:04, 6770403.27it/s]
 49%|████▉     | 28450816/58169474 [00:07<00:04, 6865181.04it/s]
 50%|█████     | 29147136/58169474 [00:07<00:04, 6888885.83it/s]
 51%|█████▏    | 29843456/58169474 [00:07<00:04, 6856628.60it/s]
 53%|█████▎    | 30564352/58169474 [00:07<00:03, 6958366.65it/s]
 54%|█████▍    | 31268864/58169474 [00:07<00:03, 6958654.86it/s]
 55%|█████▍    | 31989760/58169474 [00:07<00:03, 7032125.60it/s]
 56%|█████▌    | 32694272/58169474 [00:07<00:03, 6869851.20it/s]
 57%|█████▋    | 33415168/58169474 [00:07<00:03, 6964187.37it/s]
 59%|█████▊    | 34119680/58169474 [00:08<00:06, 3977355.11it/s]
 60%|█████▉    | 34668544/58169474 [00:08<00:07, 3199339.25it/s]
 61%|██████    | 35504128/58169474 [00:08<00:05, 4079854.70it/s]
 62%|██████▏   | 36069376/58169474 [00:08<00:05, 4130712.39it/s]
 63%|██████▎   | 36593664/58169474 [00:08<00:05, 4314789.92it/s]
 64%|██████▍   | 37134336/58169474 [00:08<00:04, 4562811.35it/s]
 65%|██████▍   | 37707776/58169474 [00:09<00:04, 4818970.81it/s]
 66%|██████▌   | 38264832/58169474 [00:09<00:03, 4999004.47it/s]
 67%|██████▋   | 38830080/58169474 [00:09<00:03, 5149728.12it/s]
 68%|██████▊   | 39378944/58169474 [00:09<00:03, 5151647.13it/s]
 69%|██████▊   | 39919616/58169474 [00:09<00:03, 5197364.32it/s]
 70%|██████▉   | 40534016/58169474 [00:09<00:03, 5405299.44it/s]
 71%|███████   | 41132032/58169474 [00:09<00:03, 5543858.91it/s]
 72%|███████▏  | 41697280/58169474 [00:09<00:02, 5514790.21it/s]
 73%|███████▎  | 42254336/58169474 [00:09<00:02, 5422164.46it/s]
 74%|███████▎  | 42876928/58169474 [00:09<00:02, 5614621.42it/s]
 75%|███████▍  | 43442176/58169474 [00:10<00:02, 5587491.23it/s]
 76%|███████▌  | 44007424/58169474 [00:10<00:02, 5481031.42it/s]
 77%|███████▋  | 44654592/58169474 [00:10<00:02, 5758667.87it/s]
 78%|███████▊  | 45268992/58169474 [00:10<00:02, 5838332.03it/s]
 79%|███████▉  | 45858816/58169474 [00:10<00:02, 5747734.50it/s]
 80%|███████▉  | 46440448/58169474 [00:10<00:02, 5764738.27it/s]
 81%|████████  | 47071232/58169474 [00:10<00:01, 5908477.14it/s]
 82%|████████▏ | 47669248/58169474 [00:10<00:01, 5737853.16it/s]
 83%|████████▎ | 48250880/58169474 [00:10<00:01, 5751655.96it/s]
 84%|████████▍ | 48840704/58169474 [00:11<00:01, 5783791.03it/s]
 85%|████████▍ | 49422336/58169474 [00:11<00:01, 5538253.41it/s]
 86%|████████▌ | 50069504/58169474 [00:11<00:01, 5803445.40it/s]
 87%|████████▋ | 50659328/58169474 [00:11<00:01, 5818860.34it/s]
 88%|████████▊ | 51257344/58169474 [00:11<00:01, 5842790.98it/s]
 89%|████████▉ | 51863552/58169474 [00:11<00:01, 5839985.10it/s]
 90%|█████████ | 52518912/58169474 [00:11<00:00, 6000478.20it/s]
 91%|█████████▏| 53125120/58169474 [00:11<00:00, 5973870.06it/s]
 92%|█████████▏| 53723136/58169474 [00:11<00:00, 5932396.26it/s]
 93%|█████████▎| 54345728/58169474 [00:11<00:00, 5929362.04it/s]
 94%|█████████▍| 54943744/58169474 [00:12<00:00, 5862692.71it/s]
 95%|█████████▌| 55533568/58169474 [00:12<00:00, 5866055.22it/s]
 97%|█████████▋| 56139776/58169474 [00:12<00:00, 5911343.19it/s]
 98%|█████████▊| 56737792/58169474 [00:12<00:00, 5851072.56it/s]
 99%|█████████▊| 57401344/58169474 [00:12<00:00, 6043333.55it/s]
100%|█████████▉| 58032128/58169474 [00:12<00:00, 6118414.59it/s]
58171392it [00:12, 4625473.27it/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.768 seconds)

Gallery generated by Sphinx-Gallery