Recent Releases of torchio
torchio - v0.20.21
What's Changed
- Throw error on wrong files shape by @emmanuel-ferdman in https://github.com/TorchIO-project/torchio/pull/1357
- Improve colors in label map plots by @fepegar in https://github.com/TorchIO-project/torchio/pull/1362
- Add option to pass kwargs for savefig by @fepegar in https://github.com/TorchIO-project/torchio/pull/1363
- Stop copying whole image before cropping (again) by @fepegar in https://github.com/TorchIO-project/torchio/pull/1360
New Contributors
- @emmanuel-ferdman made their first contribution in https://github.com/TorchIO-project/torchio/pull/1357
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.20...v0.20.21
- Python
Published by fepegar 7 months ago
torchio - v0.20.20
What's Changed
- Remove keep_components kwarg in PCA by @fepegar in https://github.com/TorchIO-project/torchio/pull/1355
- Fix links to documentation by @fepegar in https://github.com/TorchIO-project/torchio/pull/1354
- Replace np.copy with np.ascontiguousarray by @fepegar in https://github.com/TorchIO-project/torchio/pull/1356
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.19...v0.20.20
- Python
Published by fepegar 7 months ago
torchio - v0.20.19
What's Changed
- Stop loading image by default with
tiohdby @fepegar in https://github.com/TorchIO-project/torchio/pull/1344 - Add
Totransform by @fepegar in https://github.com/TorchIO-project/torchio/pull/1345 - Add support to export images as videos by @fepegar in https://github.com/TorchIO-project/torchio/pull/1346
- Add workflow to build and deploy documentation by @fepegar in https://github.com/TorchIO-project/torchio/pull/1347
- Remove references to Read the Docs by @fepegar in https://github.com/TorchIO-project/torchio/pull/1348
- Add
Transposetransform by @fepegar in https://github.com/TorchIO-project/torchio/pull/1350 - Add tools to visualize embeddings in input space (
ToReferenceSpaceandPCA) by @fepegar in https://github.com/TorchIO-project/torchio/pull/1349 - Update links to docs by @fepegar in https://github.com/TorchIO-project/torchio/pull/1351
- Unpin
uv-buildby @fepegar in https://github.com/TorchIO-project/torchio/pull/1352
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.18...v0.20.19
- Python
Published by fepegar 7 months ago
torchio - v0.20.18
What's Changed
- Use better colormap for label maps by @fepegar in https://github.com/TorchIO-project/torchio/pull/1338
- Use uv as build backend by @fepegar in https://github.com/TorchIO-project/torchio/pull/1339
- Revert warning when SubjectsLoader is not used by @fepegar in https://github.com/TorchIO-project/torchio/pull/1340
- Add some missing args names by @fepegar in https://github.com/TorchIO-project/torchio/pull/1343
- Stop verifying image paths in CT-RATE by @fepegar in https://github.com/TorchIO-project/torchio/pull/1341
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.17...v0.20.18
- Python
Published by fepegar 8 months ago
torchio - v0.20.16
What's Changed
- Improve error when a tensor is passed to an image by @fepegar in https://github.com/TorchIO-project/torchio/pull/1334
- Use global statistics in Pad (and CropOrPad) by @fepegar in https://github.com/TorchIO-project/torchio/pull/1336
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.15...v0.20.16
- Python
Published by fepegar 8 months ago
torchio - v0.20.15
What's Changed
- Add zone plate test image by @fepegar in https://github.com/TorchIO-project/torchio/pull/1326
- Improve plots of datasets classes by @fepegar in https://github.com/TorchIO-project/torchio/pull/1325
- Add option to not verify image path by @fepegar in https://github.com/TorchIO-project/torchio/pull/1324
- Add defaultpadlabel parameter to [Random]Affine by @copilot-swe-agent in https://github.com/TorchIO-project/torchio/pull/1330
New Contributors
- @copilot-swe-agent made their first contribution in https://github.com/TorchIO-project/torchio/pull/1323
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.14...v0.20.15
- Python
Published by fepegar 8 months ago
torchio - v0.20.11
What's Changed
- Add nice error message when using wrong Slicer key by @fepegar in https://github.com/TorchIO-project/torchio/pull/1309
- Add support to set figure title in plot method by @toufiqmusah in https://github.com/TorchIO-project/torchio/pull/1306
- Add support to propagate kwargs in Image.plot by @fepegar in https://github.com/TorchIO-project/torchio/pull/1315
- Make resampling symmetric by @fepegar in https://github.com/TorchIO-project/torchio/pull/1310
New Contributors
- @toufiqmusah made their first contribution in https://github.com/TorchIO-project/torchio/pull/1306
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.10...v0.20.11
- Python
Published by fepegar 8 months ago
torchio - v0.20.10
What's Changed
- Stop copying whole image before cropping by @StijnvWijn in https://github.com/TorchIO-project/torchio/pull/1308
- Stop using Optional for type annotations by @fepegar in https://github.com/TorchIO-project/torchio/pull/1299
New Contributors
- @StijnvWijn made their first contribution in https://github.com/TorchIO-project/torchio/pull/1308
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.9...v0.20.10
- Python
Published by fepegar 8 months ago
torchio - v0.20.9
What's Changed
- Add combined affine and elastic deformation augmentation by @mrdkucher in https://github.com/TorchIO-project/torchio/pull/1073
New Contributors
- @mrdkucher made their first contribution in https://github.com/TorchIO-project/torchio/pull/1073
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.8...v0.20.9
- Python
Published by fepegar 10 months ago
torchio - v0.20.8
What's Changed
- Add option to skip crop or pad in CropOrPad by @rickymwalsh in https://github.com/TorchIO-project/torchio/pull/1295
New Contributors
- @rickymwalsh made their first official contribution in https://github.com/TorchIO-project/torchio/pull/1295
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.7...v0.20.8
- Python
Published by fepegar 10 months ago
torchio - v0.20.7
What's Changed
- Replace DeprecationWarning with FutureWarning by @fepegar in https://github.com/TorchIO-project/torchio/pull/1289
- Add ToOrientation transformation by @mueller-franzes in https://github.com/TorchIO-project/torchio/pull/1290
New Contributors
- @erooke made their first contribution in https://github.com/TorchIO-project/torchio/pull/1285
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.6...v0.20.7
- Python
Published by fepegar 10 months ago
torchio - v0.20.6
What's Changed
- Fix RandomAnisotropy changing spatial shape of Subject with copy=False by @nicoloesch in https://github.com/TorchIO-project/torchio/pull/1276
- Fix unnecessary parameter from parent class by @fepegar in https://github.com/TorchIO-project/torchio/pull/1277
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.5...v0.20.6
- Python
Published by fepegar 11 months ago
torchio - v0.20.5
What's Changed
- Pin dependencies in groups by @fepegar in https://github.com/TorchIO-project/torchio/pull/1265
- Update repository URL everywhere by @fepegar in https://github.com/TorchIO-project/torchio/pull/1263
- Update comment to reflect correct dimensionality in
nib_to_sitkfunction by @RJacobArthrex in https://github.com/TorchIO-project/torchio/pull/1270 - Rename typing module to types by @fepegar in https://github.com/TorchIO-project/torchio/pull/1273
New Contributors
- @RJacobArthrex made their first contribution in https://github.com/TorchIO-project/torchio/pull/1270
Full Changelog: https://github.com/TorchIO-project/torchio/compare/v0.20.4...v0.20.5
- Python
Published by fepegar 11 months ago
torchio - v0.20.3
What's Changed
- Split extra dependencies and dependency groups by @fepegar in https://github.com/fepegar/torchio/pull/1238
- Add lower bounds to dependencies by @fepegar in https://github.com/fepegar/torchio/pull/1246
Full Changelog: https://github.com/fepegar/torchio/compare/v0.20.2...v0.20.3
- Python
Published by fepegar about 1 year ago
torchio - v0.20.2
What's Changed
- Implement missing restore feature for RandomGhosting by @fepegar in https://github.com/fepegar/torchio/pull/1211
- Remove support for Python 3.8 by @fepegar in https://github.com/fepegar/torchio/pull/1236
Full Changelog: https://github.com/fepegar/torchio/compare/v0.20.1...v0.20.2
- Python
Published by fepegar about 1 year ago
torchio - v0.18.88
What's Changed
- Improve support for queue in distributed training by @hsyang1222 in https://github.com/fepegar/torchio/pull/1021
- Remove Visible Human Project datasets by @fepegar in https://github.com/fepegar/torchio/pull/1026
- Make subject parameter mandatory by @fepegar in https://github.com/fepegar/torchio/pull/1029
Other Changes
- Disable Windows tests on Python 3.10 temporarily by @fepegar in https://github.com/fepegar/torchio/pull/1024
- [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/fepegar/torchio/pull/997
- Avoid duplicate CI runs by @fepegar in https://github.com/fepegar/torchio/pull/1027
- Add support for Python 3.11 by @fepegar in https://github.com/fepegar/torchio/pull/1008
- Stop ignoring import errors for mypy by @fepegar in https://github.com/fepegar/torchio/pull/1028
- docs: add arthursw as a contributor for bug, and doc by @allcontributors in https://github.com/fepegar/torchio/pull/1030
- Fix new mypy errors from nibabel by @fepegar in https://github.com/fepegar/torchio/pull/1032
- Fix flake8 errors by @fepegar in https://github.com/fepegar/torchio/pull/1036
- Try setting up workflow to run on PRs by @fepegar in https://github.com/fepegar/torchio/pull/1037
- docs: add hsyang1222 as a contributor for code by @allcontributors in https://github.com/fepegar/torchio/pull/1038
New Contributors
- @hsyang1222 made their first contribution in https://github.com/fepegar/torchio/pull/1021
Full Changelog: https://github.com/fepegar/torchio/compare/v0.18.87...v0.18.88
- Python
Published by fepegar over 1 year ago
torchio - v0.18.89
What's Changed
- Stop ignoring intensity transforms when computing inverse by @fepegar in https://github.com/fepegar/torchio/pull/1039
- Add support to invert RescaleIntensity transform by @nicoloesch in https://github.com/fepegar/torchio/pull/998
Other Changes
- docs: add nicoloesch as a contributor for code by @allcontributors in https://github.com/fepegar/torchio/pull/1040
New Contributors
- @nicoloesch made their first contribution in https://github.com/fepegar/torchio/pull/998
Full Changelog: https://github.com/fepegar/torchio/compare/v0.18.88...v0.18.89
- Python
Published by fepegar over 1 year ago
torchio - v0.18.91
What's Changed
- Warn if 'mean' padding mode is used for label maps by @fepegar in https://github.com/fepegar/torchio/pull/1065
Other Changes
- Create flake8 config section by @fepegar in https://github.com/fepegar/torchio/pull/1046
- Add black autoformatting by @fepegar in https://github.com/fepegar/torchio/pull/1031
- Split CI workflows by @fepegar in https://github.com/fepegar/torchio/pull/1047
- Add docformatter hook by @fepegar in https://github.com/fepegar/torchio/pull/1048
- [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1050
- docs: add sbdoherty as a contributor for doc by @allcontributors in https://github.com/fepegar/torchio/pull/1060
- Fix mypy error from NiBabel by @fepegar in https://github.com/fepegar/torchio/pull/1064
- [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1066
- Use new codecov method to upload coverage by @fepegar in https://github.com/fepegar/torchio/pull/1069
Full Changelog: https://github.com/fepegar/torchio/compare/v0.18.90...v0.18.91
- Python
Published by fepegar over 1 year ago
torchio - v0.18.92
What's Changed
- Fix unloaded image affine not read after CopyAffine by @fepegar in https://github.com/fepegar/torchio/pull/1072
- Fix custom reader not propagated when copying by @fepegar in https://github.com/fepegar/torchio/pull/1091
Other Changes
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1074
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1076
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1077
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1090
Full Changelog: https://github.com/fepegar/torchio/compare/v0.18.91...v0.18.92
- Python
Published by fepegar over 1 year ago
torchio - v0.19.0
What's Changed
- Remove support for Python 3.7 by @fepegar in https://github.com/fepegar/torchio/pull/1099
Other Changes
- docs: add Zhack47 as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1092
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1094
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1097
Full Changelog: https://github.com/fepegar/torchio/compare/v0.18.92...v0.19.0
- Python
Published by fepegar over 1 year ago
torchio - v0.19.1
What's Changed
- Fix silenced exception in Queue when using faulty transform by @Zhack47 in https://github.com/fepegar/torchio/pull/1101
Other Changes
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1100
New Contributors
- @Zhack47 made their first contribution in https://github.com/fepegar/torchio/pull/1101
Full Changelog: https://github.com/fepegar/torchio/compare/v0.19.0...v0.19.1
- Python
Published by fepegar over 1 year ago
torchio - v0.19.2
What's Changed
- Fix
RescaleIntensityby @fepegar in https://github.com/fepegar/torchio/pull/1116
Other Changes
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1105
- Fix type hints in RandomMotion by @blakedewey in https://github.com/fepegar/torchio/pull/1104
- docs: add blakedewey as a contributor for doc by @allcontributors in https://github.com/fepegar/torchio/pull/1107
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1109
- Bump actions/checkout from 3 to 4 by @dependabot in https://github.com/fepegar/torchio/pull/1103
- Upgrade black by @fepegar in https://github.com/fepegar/torchio/pull/1113
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1111
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1118
- Specify Python version for RTD build by @fepegar in https://github.com/fepegar/torchio/pull/1119
- docs: add nicoloesch as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1121
- docs: add romainVala as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1122
- docs: add mueller-franzes as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1123
New Contributors
- @blakedewey made their first contribution in https://github.com/fepegar/torchio/pull/1104
Full Changelog: https://github.com/fepegar/torchio/compare/v0.19.1...v0.19.2
- Python
Published by fepegar over 1 year ago
torchio - v0.19.3
What's Changed
- Queue length modification with the use of DDP by @haughty-yeon in https://github.com/fepegar/torchio/pull/1127
Other changes
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1124
- docs: add haughty-yeon as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1128
New Contributors
- @haughty-yeon made their first contribution in https://github.com/fepegar/torchio/pull/1127
Full Changelog: https://github.com/fepegar/torchio/compare/v0.19.2...v0.19.3
- Python
Published by fepegar over 1 year ago
torchio - v0.19.4
What's Changed
- Fix getsubjectsfrom_batch ignoring metadata by @KonoMaxi in https://github.com/fepegar/torchio/pull/1131
Other changes
- Upgrade black by @fepegar in https://github.com/fepegar/torchio/pull/1133
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1134
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1135
- Bump actions/setup-python from 4 to 5 by @dependabot in https://github.com/fepegar/torchio/pull/1132
- Ignore new flake8 error by @fepegar in https://github.com/fepegar/torchio/pull/1138
- docs: add KonoMaxi as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1141
New Contributors
- @KonoMaxi made their first contribution in https://github.com/fepegar/torchio/pull/1131
Full Changelog: https://github.com/fepegar/torchio/compare/v0.19.3...v0.19.4
- Python
Published by fepegar over 1 year ago
torchio - v0.19.5
What's Changed
- Add masking_method arg name in Mask by @lchauvin in https://github.com/fepegar/torchio/pull/1137
Other changes
- Fix errors after new Black version by @fepegar in https://github.com/fepegar/torchio/pull/1140
- Fix random errors in queue test by @fepegar in https://github.com/fepegar/torchio/pull/1142
- docs: add lchauvin as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1143
New Contributors
- @lchauvin made their first contribution in https://github.com/fepegar/torchio/pull/1137
Full Changelog: https://github.com/fepegar/torchio/compare/v0.19.4...v0.19.5
- Python
Published by fepegar over 1 year ago
torchio - v0.19.6
What's Changed
- Enable plotting of PNG images with alpha channel by @ChristianHinge in https://github.com/fepegar/torchio/pull/1150
- Fix transforms taking strings instead of sequences by @fepegar in https://github.com/fepegar/torchio/pull/1153
Other changes
- Fix new Black errors by @fepegar in https://github.com/fepegar/torchio/pull/1145
- Run tests on Python 3.12 by @fepegar in https://github.com/fepegar/torchio/pull/1114
- Cover more Python versions in other OSs by @fepegar in https://github.com/fepegar/torchio/pull/1146
- Upload coverage only for Ubuntu and Python 3.12 by @fepegar in https://github.com/fepegar/torchio/pull/1147
- Skip slow tests except for scheduled jobs by @fepegar in https://github.com/fepegar/torchio/pull/1148
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1151
- docs: add ChristianHinge as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1152
- docs: add zzz123xyz as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1154
New Contributors
- @ChristianHinge made their first contribution in https://github.com/fepegar/torchio/pull/1150
Full Changelog: https://github.com/fepegar/torchio/compare/v0.19.5...v0.19.6
- Python
Published by fepegar over 1 year ago
torchio - v0.19.7
What's Changed
- Set upper bound of PyTorch version by @fepegar in https://github.com/fepegar/torchio/pull/1178
- Add support to slice images and subjects by @fepegar in https://github.com/fepegar/torchio/pull/1170
Other changes
- Fix example in docs by @fepegar in https://github.com/fepegar/torchio/pull/1160
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1156
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1164
- Improve docs for "isotropic" arg in RandomAffine by @AminAlam in https://github.com/fepegar/torchio/pull/1163
- docs: add AminAlam as a contributor for doc by @allcontributors in https://github.com/fepegar/torchio/pull/1166
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1167
- Update Python version in CI by @fepegar in https://github.com/fepegar/torchio/pull/1149
- docs: add marius-sm as a contributor for ideas by @allcontributors in https://github.com/fepegar/torchio/pull/1172
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1176
New Contributors
- @AminAlam made their first contribution in https://github.com/fepegar/torchio/pull/1163
Full Changelog: https://github.com/fepegar/torchio/compare/v0.19.6...v0.19.7
- Python
Published by fepegar over 1 year ago
torchio - v0.19.9
What's Changed
- Make transform return the same type as input by @haarisr in https://github.com/fepegar/torchio/pull/1182
Others
- docs: add haarisr as a contributor for code by @allcontributors in https://github.com/fepegar/torchio/pull/1184
New Contributors
- @haarisr made their first contribution in https://github.com/fepegar/torchio/pull/1182
Full Changelog: https://github.com/fepegar/torchio/compare/v0.19.8...v0.19.9
- Python
Published by fepegar over 1 year ago
torchio - v0.20.0
Main changes
- Add SubjectsLoader by @fepegar in https://github.com/fepegar/torchio/pull/1194
- Fix error which copying a subclass of Subject with keyword attributes by @c-winder in https://github.com/fepegar/torchio/pull/1186
Others
- docs: add c-winder as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1193
- Fix intersphinx mapping error by @fepegar in https://github.com/fepegar/torchio/pull/1192
- Update typer dependency by @fepegar in https://github.com/fepegar/torchio/pull/1191
- docs: add rickymwalsh as a contributor for bug, and code by @allcontributors in https://github.com/fepegar/torchio/pull/1197
- Use OIDC for TestPyPI and PyPI by @fepegar in https://github.com/fepegar/torchio/pull/1195
New Contributors
- @c-winder made their first contribution in https://github.com/fepegar/torchio/pull/1186
Full Changelog: https://github.com/fepegar/torchio/compare/v0.19.9...v0.20.0
- Python
Published by fepegar over 1 year ago
torchio - v0.20.1
Main changes
- Add warning if SubjectsLoader is not used in PyTorch >= 2.3 by @fepegar in https://github.com/fepegar/torchio/pull/1215
- Fix KeyError with LabelMap-only subjects by @fepegar in https://github.com/fepegar/torchio/pull/1218
Maintenance changes
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1180
- Remove setup.cfg by @fepegar in https://github.com/fepegar/torchio/pull/1198
- Use tox-uv for tests by @fepegar in https://github.com/fepegar/torchio/pull/1199
- Fix Codecov CI by @fepegar in https://github.com/fepegar/torchio/pull/1200
- Decrease verbosity of unit tests by @fepegar in https://github.com/fepegar/torchio/pull/1201
- Use tox-uv for code quality CI by @fepegar in https://github.com/fepegar/torchio/pull/1202
- Use Ruff for linting by @fepegar in https://github.com/fepegar/torchio/pull/1203
- Use Ruff for formatting by @fepegar in https://github.com/fepegar/torchio/pull/1204
- Fix copy button prompt text by @fepegar in https://github.com/fepegar/torchio/pull/1206
- Remove annotations in enum by @fepegar in https://github.com/fepegar/torchio/pull/1205
- Fix linting errors by @fepegar in https://github.com/fepegar/torchio/pull/1207
- Bump codecov/codecov-action from 4.2.0 to 4.5.0 by @dependabot in https://github.com/fepegar/torchio/pull/1209
- Use pre-commit-uv dependency by @fepegar in https://github.com/fepegar/torchio/pull/1208
- Use colors in CI by @fepegar in https://github.com/fepegar/torchio/pull/1212
- Fix some links in docs by @fepegar in https://github.com/fepegar/torchio/pull/1213
- Autoupdate pre-commit hooks by @pre-commit-ci in https://github.com/fepegar/torchio/pull/1217
- Fix bumpversion and pre-commit configs by @fepegar in https://github.com/fepegar/torchio/pull/1219
Full Changelog: https://github.com/fepegar/torchio/compare/v0.20.0...v0.20.1
- Python
Published by fepegar over 1 year ago
torchio - v0.18.90
What's Changed
- Fix HistogramStandardization example by @vedal in https://github.com/fepegar/torchio/pull/1022
- docs: add vedal as a contributor for doc by @allcontributors in https://github.com/fepegar/torchio/pull/1041
- Add workflow to validate pull request title by @fepegar in https://github.com/fepegar/torchio/pull/1042
- docs: add alabamagan as a contributor for bug by @allcontributors in https://github.com/fepegar/torchio/pull/1043
- docs: add justusschock as a contributor for ideas, and review by @allcontributors in https://github.com/fepegar/torchio/pull/1044
- Add support to unload images by @fepegar in https://github.com/fepegar/torchio/pull/983
- Remove mypy config file by @fepegar in https://github.com/fepegar/torchio/pull/1045
New Contributors
- @vedal made their first contribution in https://github.com/fepegar/torchio/pull/1022
Full Changelog: https://github.com/fepegar/torchio/compare/v0.18.89...v0.18.90
- Python
Published by fepegar almost 3 years ago
torchio - TorchIO: a Python library for efficient loading, preprocessing, augmentation and patch-based sampling of medical images in deep learning
- Python
Published by fepegar about 5 years ago
torchio - Medical image preprocessing and augmentation tools for deep learning.
TorchIO is a Python package containing a set of tools to efficiently read, preprocess, sample, augment, and write 3D medical images in deep learning applications written in PyTorch, including intensity and spatial transforms for data augmentation and preprocessing. Transforms include typical computer vision operations such as random affine transformations and also domain-specific ones such as simulation of intensity artifacts due to MRI magnetic field inhomogeneity or k-space motion artifacts.
- Python
Published by fepegar over 5 years ago
torchio - Tools for medical image processing in deep learning and PyTorch
- Python
Published by fepegar almost 6 years ago
torchio - TorchIO: Tools for loading, augmenting and writing 3D medical images on PyTorch
If you use TorchIO for your research, please cite the paper:
- Python
Published by fepegar almost 6 years ago
torchio - TorchIO: Tools for loading, augmenting and writing 3D medical images with PyTorch
TorchIO is a Python package containing a set of tools to efficiently read, sample and write 3D medical images in deep learning applications written in PyTorch, including intensity and spatial transforms for data augmentation and preprocessing. Transforms include typical computer vision operations such as random affine transformations and also domain-specific ones such as simulation of intensity artifacts due to MRI magnetic field inhomogeneity or k-space motion artifacts.
- Python
Published by fepegar almost 6 years ago
torchio - TorchIO: tools for loading, augmenting and writing 3D medical images with PyTorch
TorchIO is a Python package containing a set of tools to efficiently read, sample and write 3D medical images in deep learning applications written in PyTorch, including intensity and spatial transforms for data augmentation and preprocessing. Transforms include typical computer vision operations such as random affine transformations and also domain-specific ones such as simulation of intensity artifacts due to MRI magnetic field inhomogeneity or k-space motion artifacts.
- Python
Published by fepegar about 6 years ago
torchio - TorchIO: tools for loading, augmenting and writing 3D medical images on PyTorch
TorchIO is a Python package containing a set of tools to efficiently read, sample and write 3D medical images in deep learning applications written in PyTorch, including intensity and spatial transforms for data augmentation and preprocessing. Transforms include typical computer vision operations such as random affine transformations and also domain-specific ones such as simulation of intensity artifacts due to MRI magnetic field inhomogeneity or k-space motion artifacts.
- Python
Published by fepegar about 6 years ago
torchio - TorchIO: Tools for loading, augmenting and writing 3D medical images on PyTorch
TorchIO
torchio is a Python package containing a set of tools to efficiently
read, sample and write 3D medical images in deep learning applications
written in PyTorch,
including intensity and spatial transforms
for data augmentation and preprocessing. Transforms include typical computer vision operations
such as random affine transformations and also domain specific ones such as
simulation of intensity artifacts due to
MRI magnetic field inhomogeneity
or k-space motion artifacts.
This package has been greatly inspired by NiftyNet.
Credits
If you like this repository, please click on Star!
If you used this package for your research, please cite this repository using the information available on its Zenodo entry or use this BibTeX:
bibtex
@software{perez_garcia_fernando_2020_3598622,
author = {Pérez-García, Fernando},
title = {{fepegar/torchio: TorchIO: Tools for loading,
augmenting and writing 3D medical images on
PyTorch}},
month = jan,
year = 2020,
publisher = {Zenodo},
doi = {10.5281/zenodo.3598622},
url = {https://doi.org/10.5281/zenodo.3598622}
}
Index
Installation
This package is on the Python Package Index (PyPI). To install it, just run in a terminal the following command:
shell
$ pip install torchio
Features
Data handling
ImagesDataset
ImagesDataset is a reader of medical images that directly inherits from
torch.utils.Dataset.
It can be used with a
torch.utils.DataLoader
for efficient reading and data augmentation.
It receives a list of subjects, where each subject is composed of a list of
torchio.Image instances.
The paths suffix must be .nii, .nii.gz or .nrrd.
```python import torchio
subjecta = [ Image('t1', '~/Dropbox/MRI/t1.nrrd', torchio.INTENSITY), Image('label', '~/Dropbox/MRI/t1seg.nii.gz', torchio.LABEL), ] subjectb = [ Image('t1', '/tmp/colin27t1tallin.nii.gz', torchio.INTENSITY), Image('t2', '/tmp/colin27t2tallin.nii', torchio.INTENSITY), Image('label', '/tmp/colin27seg1.nii.gz', torchio.LABEL), ] subjectslist = [subjecta, subjectb] subjectsdataset = torchio.ImagesDataset(subjectslist) subjectsample = subjects_dataset[0] ```
Samplers
torchio includes grid, uniform and label patch samplers. There is also an
aggregator used for dense predictions.
For more information about patch-based training, see
NiftyNet docs.
```python import torch import torchio
CHANNELSDIMENSION = 1 patchoverlap = 4 gridsampler = torchio.inference.GridSampler( inputarray, # some NumPy array patchsize=128, patchoverlap=patchoverlap, ) patchloader = torch.utils.data.DataLoader(gridsampler, batchsize=4) aggregator = torchio.inference.GridAggregator( inputarray, patchoverlap=patch_overlap, )
with torch.nograd(): for patchesbatch in patchloader: inputtensor = patchesbatch['image'] locations = patchesbatch['location'] logits = model(inputtensor) # some torch.nn.Module labels = logits.argmax(dim=CHANNELSDIMENSION, keepdim=True) outputs = labels aggregator.add_batch(outputs, locations)
outputarray = aggregator.outputarray ```
Queue
A patches Queue (or buffer) can be used for randomized patch-based sampling
during training.
This interactive animation
can be used to understand how the queue works.
```python import torch import torchio
patchesqueue = torchio.Queue( subjectsdataset=subjectsdataset, # instance of torchio.ImagesDataset queuelength=300, samplespervolume=10, patchsize=96, samplerclass=torchio.sampler.ImageSampler, numworkers=4, shufflesubjects=True, shufflepatches=True, ) patchesloader = DataLoader(patchesqueue, batchsize=4)
numepochs = 20 for epochindex in range(numepochs): for patchesbatch in patchesloader: logits = model(patchesbatch) # model is some torch.nn.Module ```
Transforms
The transforms package should remind users of
torchvision.transforms.
They take as input the samples generated by an ImagesDataset.
A transform can be quickly applied to an image file using the command-line
tool torchio-transform:
shell
$ torchio-transform input.nii.gz RandomMotion output.nii.gz --kwargs "proportion_to_augment=1 num_transforms=4"
Augmentation
Intensity
MRI k-space motion artifacts
Magnetic resonance images suffer from motion artifacts when the subject moves during image acquisition. This transform follows Shaw et al., 2019 to simulate motion artifacts for data augmentation.

MRI magnetic field inhomogeneity
MRI magnetic field inhomogeneity creates slow frequency intensity variations. This transform is very similar to the one in NiftyNet.

Gaussian noise
Adds noise sampled from a normal distribution with mean 0 and standard
deviation sampled from a uniform distribution in the range std_range.
It is often used after ZNormalization, as the output of
this transform has zero-mean.

Spatial
B-spline dense elastic deformation

Flip
Reverse the order of elements in an image along the given axes.
Affine transform
Preprocessing
Histogram standardization
Implementation of New variants of a method of MRI scale standardization adapted from NiftyNet.

Z-normalization
This transform first extracts the values with intensity greater than the mean, which is an approximation of the foreground voxels. Then the foreground mean is subtracted from the image and it is divided by the foreground standard deviation.

Rescale
Rescale intensity values in an image to a certain range.
Resample
Resample images to a new voxel spacing using nibabel.
Pad
Pad images, like in torchvision.transforms.Pad.
Crop
Crop images passing 1, 3, or 6 integers, as in Pad.
Example
This example shows the improvement in performance when multiple workers are used to load and preprocess the volumes using multiple workers.
```python import time import multiprocessing as mp
from tqdm import trange
import torch.nn as nn from torch.utils.data import DataLoader from torchvision.transforms import Compose
from torchio import ImagesDataset, Queue, DATA from torchio.sampler import ImageSampler from torchio.utils import createdummydataset from torchio.transforms import ( ZNormalization, RandomNoise, RandomFlip, RandomAffine, )
Define training and patches sampling parameters
numepochs = 4 patchsize = 128 queuelength = 400 samplespervolume = 10 batchsize = 4
class Network(nn.Module): def init(self): super().init() self.conv = nn.Conv3d( inchannels=1, outchannels=3, kernel_size=3, ) def forward(self, x): return self.conv(x)
model = Network()
Create a dummy dataset in the temporary directory, for this example
subjectslist = createdummydataset( numimages=100, size_range=(193, 229), force=False, )
Each element of subjects_list is a dictionary:
subject_images = [
torchio.Image('oneimage', pathtooneimage, torchio.INTENSITY),
torchio.Image('anotherimage', pathtoanotherimage, torchio.INTENSITY),
torchio.Image('alabel', pathtoalabel, torchio.LABEL),
]
Define transforms for data normalization and augmentation
transforms = ( ZNormalization(), RandomNoise(stdrange=(0, 0.25)), RandomAffine(scales=(0.9, 1.1), degrees=10), RandomFlip(axes=(0,)), ) transform = Compose(transforms) subjectsdataset = ImagesDataset(subjects_list, transform)
Run a benchmark for different numbers of workers
workers = range(mp.cpucount() + 1) for numworkers in workers: print('Number of workers:', num_workers)
# Define the dataset as a queue of patches
queue_dataset = Queue(
subjects_dataset,
queue_length,
samples_per_volume,
patch_size,
ImageSampler,
num_workers=num_workers,
)
batch_loader = DataLoader(queue_dataset, batch_size=batch_size)
start = time.time()
for epoch_index in trange(num_epochs, leave=False):
for batch in batch_loader:
# The keys of batch have been defined in create_dummy_dataset()
inputs = batch['one_modality'][DATA]
targets = batch['segmentation'][DATA]
logits = model(inputs)
print('Time:', int(time.time() - start), 'seconds')
print()
```
Output: ```python Number of workers: 0 Time: 394 seconds
Number of workers: 1 Time: 372 seconds
Number of workers: 2 Time: 278 seconds
Number of workers: 3 Time: 259 seconds
Number of workers: 4 Time: 242 seconds ```
Related projects
See also
- Python
Published by fepegar about 6 years ago
torchio - TorchIO: Tools for loading, augmenting and writing 3D medical images on PyTorch
TorchIO
torchio is a Python package containing a set of tools to efficiently
read, sample and write 3D medical images in deep learning applications
written in PyTorch,
including intensity and spatial transforms
for data augmentation and preprocessing. Transforms include typical computer vision operations
such as random affine transformations and also domain specific ones such as
simulation of intensity artifacts due to
MRI magnetic field inhomogeneity
or k-space motion artifacts.
This package has been greatly inspired by NiftyNet.
Index
Installation
shell
$ pip install torchio
Features
Data handling
ImagesDataset
ImagesDataset is a reader of medical images that directly inherits from
torch.utils.Dataset.
It can be used with a
torch.utils.DataLoader
for efficient reading and data augmentation.
The paths suffix must be .nii, .nii.gz or .nrrd.
```python import torchio
subjecta = { 't1': dict(path='~/Dropbox/MRI/t1.nii.gz', type=torchio.INTENSITY), 'label': dict(path='~/Dropbox/MRI/t1seg.nii.gz', type=torchio.LABEL), } subjectb = { 't1': dict(path='/tmp/colin27t1tallin.nii.gz', type=torchio.INTENSITY), 'label': dict(path='/tmp/colin27seg1.nii.gz', type=torchio.LABEL), } pathslist = [subjecta, subjectb] subjectsdataset = torchio.ImagesDataset(pathslist) subjectsample = subjectsdataset[0] ```
Samplers
torchio includes grid, uniform and label patch samplers. There is also an
aggregator used for dense predictions. The code for these is almost
copy-pasted from NiftyNet.
For more information about patch-based training, see NiftyNet docs.
```python import torch import torchio
CHANNELSDIMENSION = 1 patchoverlap = 4 gridsampler = torchio.inference.GridSampler( inputarray, # some NumPy array patchsize=128, patchoverlap=patchoverlap, ) patchloader = torch.utils.data.DataLoader(gridsampler, batchsize=4) aggregator = torchio.inference.GridAggregator( inputarray, patchoverlap=patch_overlap, )
with torch.nograd(): for patchesbatch in patchloader: inputtensor = patchesbatch['image'] locations = patchesbatch['location'] logits = model(inputtensor) # some torch.nn.Module labels = logits.argmax(dim=CHANNELSDIMENSION, keepdim=True) outputs = labels aggregator.add_batch(outputs, locations)
outputarray = aggregator.outputarray ```
Queue
A patches Queue (or buffer) can be used for randomized patch-based sampling
during training.
This interactive animation
can be used to understand how the queue works.
```python import torch import torchio
patchesqueue = torchio.Queue( subjectsdataset=subjectsdataset, queuelength=300, samplespervolume=10, patchsize=96, samplerclass=torchio.sampler.ImageSampler, numworkers=4, shufflesubjects=True, shufflepatches=True, ) patchesloader = DataLoader(patchesqueue, batchsize=4)
numepochs = 20 for epochindex in range(numepochs): for patchesbatch in patchesloader: logits = model(patchesbatch) # model is some torch.nn.Module ```
Transforms
The transforms package should remind users of
torchvision.transforms.
They take as input the samples generated by an
ImagesDataset.
Intensity
MRI k-space motion artifacts
Magnetic resonance images suffer from motion artifacts when the subject moves during image acquisition. This transform follows Shaw et al., 2019 to simulate motion artifacts for data augmentation.

MRI magnetic field inhomogeneity
MRI magnetic field inhomogeneity creates slow frequency intensity variations. This transform is very similar to the one in NiftyNet.

Gaussian noise
Adds noise sampled from a normal distribution with mean 0 and standard
deviation sampled from a uniform distribution in the range std_range.
It is often used after ZNormalization, as the output of
this transform has zero-mean.

Normalization
Histogram standardization
Implementation of New variants of a method of MRI scale standardization adapted from NiftyNet.

Z-normalization
This transform first extracts the values with intensity greater than the mean, which is an approximation of the foreground voxels. Then the foreground mean is subtracted from the image and it is divided by the foreground standard deviation.

Rescale
Spatial
Flip
Reverse the order of elements in an image along the given axes.
Affine transform
B-spline dense elastic deformation

Example
This example shows the improvement in performance when multiple workers are used to load and preprocess the volumes using multiple workers.
```python import time import multiprocessing as mp
from tqdm import trange
import torch.nn as nn from torch.utils.data import DataLoader from torchvision.transforms import Compose
from torchio import ImagesDataset, Queue from torchio.sampler import ImageSampler from torchio.utils import createdummydataset from torchio.transforms import ( ZNormalization, RandomNoise, RandomFlip, RandomAffine, )
Define training and patches sampling parameters
numepochs = 4 patchsize = 128 queuelength = 400 samplespervolume = 10 batchsize = 4
class Network(nn.Module): def init(self): super().init() self.conv = nn.Conv3d( inchannels=1, outchannels=3, kernel_size=3, ) def forward(self, x): return self.conv(x)
model = Network()
Create a dummy dataset in the temporary directory, for this example
subjectslist = createdummydataset( numimages=100, size_range=(193, 229), force=False, )
Each element of subjects_list is a dictionary:
subject_images = [
torchio.Image('oneimage', pathtooneimage, torchio.INTENSITY),
torchio.Image('anotherimage', pathtoanotherimage, torchio.INTENSITY),
torchio.Image('alabel', pathtoalabel, torchio.LABEL),
]
Define transforms for data normalization and augmentation
transforms = ( ZNormalization(), RandomNoise(stdrange=(0, 0.25)), RandomAffine(scales=(0.9, 1.1), degrees=10), RandomFlip(axes=(0,)), ) transform = Compose(transforms) subjectsdataset = ImagesDataset(subjects_list, transform)
Run a benchmark for different numbers of workers
workers = range(mp.cpucount() + 1) for numworkers in workers: print('Number of workers:', num_workers)
# Define the dataset as a queue of patches
queue_dataset = Queue(
subjects_dataset,
queue_length,
samples_per_volume,
patch_size,
ImageSampler,
num_workers=num_workers,
)
batch_loader = DataLoader(queue_dataset, batch_size=batch_size)
start = time.time()
for epoch_index in trange(num_epochs, leave=False):
for batch in batch_loader:
# The keys of batch have been defined in create_dummy_dataset()
inputs = batch['one_modality']['data']
targets = batch['segmentation']['data']
logits = model(inputs)
print('Time:', int(time.time() - start), 'seconds')
print()
```
Output: ```python Number of workers: 0 Time: 394 seconds
Number of workers: 1 Time: 372 seconds
Number of workers: 2 Time: 278 seconds
Number of workers: 3 Time: 259 seconds
Number of workers: 4 Time: 242 seconds ```
- Python
Published by fepegar about 6 years ago
torchio - TorchIO: Tools for loading, augmenting and writing 3D medical images on PyTorch
TorchIO
torchio is a Python package containing a set of tools to efficiently
read, sample and write 3D medical images in deep learning applications
written in PyTorch,
including intensity and spatial transforms
for data augmentation and preprocessing. Transforms include typical computer vision operations
such as random affine transformations and also domain specific ones such as
simulation of intensity artifacts due to
MRI magnetic field inhomogeneity
or k-space motion artifacts.
This package has been greatly inspired by NiftyNet.
Index
Installation
shell
$ pip install torchio
Features
Data handling
ImagesDataset
ImagesDataset is a reader of medical images that directly inherits from
torch.utils.Dataset.
It can be used with a
torch.utils.DataLoader
for efficient reading and data augmentation.
The paths suffix must be .nii, .nii.gz or .nrrd.
```python import torchio
subjecta = { 't1': dict(path='~/Dropbox/MRI/t1.nii.gz', type=torchio.INTENSITY), 'label': dict(path='~/Dropbox/MRI/t1seg.nii.gz', type=torchio.LABEL), } subjectb = { 't1': dict(path='/tmp/colin27t1tallin.nii.gz', type=torchio.INTENSITY), 'label': dict(path='/tmp/colin27seg1.nii.gz', type=torchio.LABEL), } pathslist = [subjecta, subjectb] subjectsdataset = torchio.ImagesDataset(pathslist) subjectsample = subjectsdataset[0] ```
Samplers
torchio includes grid, uniform and label patch samplers. There is also an
aggregator used for dense predictions. The code for these is almost
copy-pasted from NiftyNet.
For more information about patch-based training, see NiftyNet docs.
```python import torch import torchio
CHANNELSDIMENSION = 1 patchoverlap = 4 gridsampler = torchio.inference.GridSampler( inputarray, # some NumPy array patchsize=128, patchoverlap=patchoverlap, ) patchloader = torch.utils.data.DataLoader(gridsampler, batchsize=4) aggregator = torchio.inference.GridAggregator( inputarray, patchoverlap=patch_overlap, )
with torch.nograd(): for patchesbatch in patchloader: inputtensor = patchesbatch['image'] locations = patchesbatch['location'] logits = model(inputtensor) # some torch.nn.Module labels = logits.argmax(dim=CHANNELSDIMENSION, keepdim=True) outputs = labels aggregator.add_batch(outputs, locations)
outputarray = aggregator.outputarray ```
Queue
A patches Queue (or buffer) can be used for randomized patch-based sampling
during training.
This interactive animation
can be used to understand how the queue works.
```python import torch import torchio
patchesqueue = torchio.Queue( subjectsdataset=subjectsdataset, queuelength=300, samplespervolume=10, patchsize=96, samplerclass=torchio.sampler.ImageSampler, numworkers=4, shufflesubjects=True, shufflepatches=True, ) patchesloader = DataLoader(patchesqueue, batchsize=4)
numepochs = 20 for epochindex in range(numepochs): for patchesbatch in patchesloader: logits = model(patchesbatch) # model is some torch.nn.Module ```
Transforms
The transforms package should remind users of
torchvision.transforms.
They take as input the samples generated by an
ImagesDataset.
Intensity
MRI k-space motion artifacts
Magnetic resonance images suffer from motion artifacts when the subject moves during image acquisition. This transform follows Shaw et al., 2019 to simulate motion artifacts for data augmentation.

MRI magnetic field inhomogeneity
MRI magnetic field inhomogeneity creates slow frequency intensity variations. This transform is very similar to the one in NiftyNet.

Gaussian noise
Adds noise sampled from a normal distribution with mean 0 and standard
deviation sampled from a uniform distribution in the range std_range.
It is often used after ZNormalization, as the output of
this transform has zero-mean.

Normalization
Histogram standardization
Implementation of New variants of a method of MRI scale standardization adapted from NiftyNet.

Z-normalization
Rescale
Spatial
Flip
Reverse the order of elements in an image along the given axes.
Affine transform
B-spline dense elastic deformation

Example
This example shows the improvement in performance when multiple workers are used to load and preprocess the volumes using multiple workers.
```python import time import multiprocessing as mp
from torch.utils.data import DataLoader from torchvision.transforms import Compose
from torchio import ImagesDataset, Queue from torchio.sampler import ImageSampler from torchio.utils import createdummydataset from torchio.transforms import ( ZNormalization, RandomNoise, RandomFlip, RandomAffine, )
Define training and patches sampling parameters
numepochs = 4 patchsize = 128 queuelength = 100 samplespervolume = 10 batchsize = 4
def model(batch, sleeptime=0.1): """Dummy function to simulate a forward pass through the network""" time.sleep(sleeptime) return batch
Create a dummy dataset in the temporary directory, for this example
subjectspaths = createdummydataset( numimages=100, size_range=(193, 229), force=False, )
Each element of subjects_paths is a dictionary:
subject = {
'oneimage': dict(path=pathtooneimage, type=torchio.INTENSITY),
'anotherimage': dict(path=pathtoanotherimage, type=torchio.INTENSITY),
'alabel': dict(path=pathtoalabel, type=torchio.LABEL),
}
Define transforms for data normalization and augmentation
transforms = ( ZNormalization(), RandomNoise(stdrange=(0, 0.25)), RandomAffine(scales=(0.9, 1.1), degrees=10), RandomFlip(axes=(0,)), ) transform = Compose(transforms) subjectsdataset = ImagesDataset(subjects_paths, transform)
sample = subjects_dataset[0]
Run a benchmark for different numbers of workers
workers = range(mp.cpucount() + 1) for numworkers in workers: print('Number of workers:', num_workers)
# Define the dataset as a queue of patches
queue_dataset = Queue(
subjects_dataset,
queue_length,
samples_per_volume,
patch_size,
ImageSampler,
num_workers=num_workers,
)
batch_loader = DataLoader(queue_dataset, batch_size=batch_size)
start = time.time()
for epoch_index in range(num_epochs):
for batch in batch_loader:
logits = model(batch)
print('Time:', int(time.time() - start), 'seconds')
print()
```
Output: ```python Number of workers: 0 Time: 394 seconds
Number of workers: 1 Time: 372 seconds
Number of workers: 2 Time: 278 seconds
Number of workers: 3 Time: 259 seconds
Number of workers: 4 Time: 242 seconds ```
- Python
Published by fepegar about 6 years ago
torchio - TorchIO: Tools for loading, augmenting and writing 3D medical images on PyTorch.
TorchIO
torchio is a Python package containing a set of tools to efficiently
read, sample and write 3D medical images in deep learning applications
written in PyTorch,
including intensity and spatial transforms
for data augmentation. Transforms include typical computer vision operations
such as random affine transformations and also domain specific ones such as
simulation of intensity artifacts due to
MRI magnetic field inhomogeneity
or k-space motion artifacts.
This package has been greatly inspired by NiftyNet.
Index
Installation
shell
$ pip install torchio
Features
Data handling
ImagesDataset
ImagesDataset is a reader of medical images that directly inherits from
torch.utils.Dataset.
It can be used with a
torch.utils.DataLoader
for efficient reading and data augmentation.
The paths suffix must be .nii, .nii.gz or .nrrd.
```python import torchio
subjecta = { 't1': dict(path='~/Dropbox/MRI/t1.nii.gz', type=torchio.INTENSITY), 'label': dict(path='~/Dropbox/MRI/t1seg.nii.gz', type=torchio.LABEL), } subjectb = { 't1': dict(path='/tmp/colin27t1tallin.nii.gz', type=torchio.INTENSITY), 'label': dict(path='/tmp/colin27seg1.nii.gz', type=torchio.LABEL), } pathslist = [subjecta, subjectb] subjectsdataset = torchio.ImagesDataset(pathslist) subjectsample = subjectsdataset[0] ```
Samplers
torchio includes grid, uniform and label patch samplers. There is also an
aggregator used for dense predictions. The code for these is almost
copy-pasted from NiftyNet.
For more information about patch-based training, see NiftyNet docs.
```python import torch import torchio
CHANNELSDIMENSION = 1 patchoverlap = 4 gridsampler = torchio.inference.GridSampler( inputarray, # some NumPy array patchsize=128, patchoverlap=patchoverlap, ) patchloader = torch.utils.data.DataLoader(gridsampler, batchsize=4) aggregator = torchio.inference.GridAggregator( inputarray, patchoverlap=patch_overlap, )
with torch.nograd(): for patchesbatch in patchloader: inputtensor = patchesbatch['image'] locations = patchesbatch['location'] logits = model(inputtensor) # some torch.nn.Module labels = logits.argmax(dim=CHANNELSDIMENSION, keepdim=True) outputs = labels aggregator.add_batch(outputs, locations)
outputarray = aggregator.outputarray ```
Queue
A patches Queue (or buffer) can be used for randomized patch-based sampling
during training.
This interactive animation
can be used to understand how the queue works.
```python import torch import torchio
patchesqueue = torchio.Queue( subjectsdataset=subjectsdataset, queuelength=300, samplespervolume=10, patchsize=96, samplerclass=torchio.sampler.ImageSampler, numworkers=4, shufflesubjects=True, shufflepatches=True, ) patchesloader = DataLoader(patchesqueue, batchsize=4)
numepochs = 20 for epochindex in range(numepochs): for patchesbatch in patchesloader: logits = model(patchesbatch) # model is some torch.nn.Module ```
Transforms
The transforms package should remind users of
torchvision.transforms.
They take as input the samples generated by an
ImagesDataset.
Intensity
MRI k-space motion artifacts
Magnetic resonance images suffer from motion artifacts when the subject moves during image acquisition. This transform follows Shaw et al., 2019 to simulate motion artifacts for data augmentation.

MRI magnetic field inhomogeneity
MRI magnetic field inhomogeneity creates slow frequency intensity variations. This transform is very similar to the one in NiftyNet.

Gaussian noise
Adds noise sampled from a normal distribution with mean 0 and standard
deviation sampled from a uniform distribution in the range std_range.
It is often used after ZNormalization, as the output of
this transform has zero-mean.

Normalization
Histogram standardization
Implementation of New variants of a method of MRI scale standardization adapted from NiftyNet.

Z-normalization
Rescale
Spatial
Flip
Reverse the order of elements in an image along the given axes.
Affine transform
B-spline dense elastic deformation

Example
This example shows the improvement in performance when multiple workers are used to load and preprocess the volumes using multiple workers.
```python import time import multiprocessing as mp
from torch.utils.data import DataLoader from torchvision.transforms import Compose
from torchio import ImagesDataset, Queue from torchio.sampler import ImageSampler from torchio.utils import createdummydataset from torchio.transforms import ( ZNormalization, RandomNoise, RandomFlip, RandomAffine, )
Define training and patches sampling parameters
numepochs = 4 patchsize = 128 queuelength = 100 samplespervolume = 10 batchsize = 4
def model(batch, sleeptime=0.1): """Dummy function to simulate a forward pass through the network""" time.sleep(sleeptime) return batch
Create a dummy dataset in the temporary directory, for this example
subjectspaths = createdummydataset( numimages=100, size_range=(193, 229), force=False, )
Each element of subjects_paths is a dictionary:
subject = {
'oneimage': dict(path=pathtooneimage, type=torchio.INTENSITY),
'anotherimage': dict(path=pathtoanotherimage, type=torchio.INTENSITY),
'alabel': dict(path=pathtoalabel, type=torchio.LABEL),
}
Define transforms for data normalization and augmentation
transforms = ( ZNormalization(), RandomNoise(stdrange=(0, 0.25)), RandomAffine(scales=(0.9, 1.1), degrees=10), RandomFlip(axes=(0,)), ) transform = Compose(transforms) subjectsdataset = ImagesDataset(subjects_paths, transform)
sample = subjects_dataset[0]
Run a benchmark for different numbers of workers
workers = range(mp.cpucount() + 1) for numworkers in workers: print('Number of workers:', num_workers)
# Define the dataset as a queue of patches
queue_dataset = Queue(
subjects_dataset,
queue_length,
samples_per_volume,
patch_size,
ImageSampler,
num_workers=num_workers,
)
batch_loader = DataLoader(queue_dataset, batch_size=batch_size)
start = time.time()
for epoch_index in range(num_epochs):
for batch in batch_loader:
logits = model(batch)
print('Time:', int(time.time() - start), 'seconds')
print()
```
Output: ```python Number of workers: 0 Time: 394 seconds
Number of workers: 1 Time: 372 seconds
Number of workers: 2 Time: 278 seconds
Number of workers: 3 Time: 259 seconds
Number of workers: 4 Time: 242 seconds ```
- Python
Published by fepegar about 6 years ago