Code Monkey home page Code Monkey logo

torchio's Introduction

TorchIO logo

Tools like TorchIO are a symptom of the maturation of medical AI research using deep learning techniques.

Jack Clark, Policy Director at OpenAI (link).


Package PyPI downloads PyPI version Conda version
CI Tests status Documentation status Coverage status
Code Code quality Code quality Code maintainability pre-commit
Tutorials Google Colab
Community Slack Twitter Twitter YouTube

Progressive artifacts

Augmentation


Original Random blur
Original Random blur
Random flip Random noise
Random flip Random noise
Random affine transformation Random elastic transformation
Random affine transformation Random elastic transformation
Random bias field artifact Random motion artifact
Random bias field artifact Random motion artifact
Random spike artifact Random ghosting artifact
Random spike artifact Random ghosting artifact

Queue

(Queue for patch-based training)


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.

This package has been greatly inspired by NiftyNet, which is not actively maintained anymore.

Credits

If you like this repository, please click on Star!

If you use this package for your research, please cite our paper:

F. Pérez-García, R. Sparks, and S. Ourselin. TorchIO: a Python library for efficient loading, preprocessing, augmentation and patch-based sampling of medical images in deep learning. Computer Methods and Programs in Biomedicine (June 2021), p. 106236. ISSN: 0169-2607.doi:10.1016/j.cmpb.2021.106236.

BibTeX entry:

@article{perez-garcia_torchio_2021,
    title = {TorchIO: a Python library for efficient loading, preprocessing, augmentation and patch-based sampling of medical images in deep learning},
    journal = {Computer Methods and Programs in Biomedicine},
    pages = {106236},
    year = {2021},
    issn = {0169-2607},
    doi = {https://doi.org/10.1016/j.cmpb.2021.106236},
    url = {https://www.sciencedirect.com/science/article/pii/S0169260721003102},
    author = {P{\'e}rez-Garc{\'i}a, Fernando and Sparks, Rachel and Ourselin, S{\'e}bastien},
}

This project is supported by the following institutions:

Getting started

See Getting started for installation instructions and a Hello, World! example.

Longer usage examples can be found in the tutorials.

All the documentation is hosted on Read the Docs.

Please open a new issue if you think something is missing.

Contributors

Thanks goes to all these people (emoji key):

Fernando Pérez-García
Fernando Pérez-García

💻 📖
valabregue
valabregue

🤔 👀 💻 💬 🐛
GFabien
GFabien

💻 👀 🤔
G.Reguig
G.Reguig

💻
Niels Schurink
Niels Schurink

💻
Ibrahim Hadzic
Ibrahim Hadzic

🐛
ReubenDo
ReubenDo

🤔
Julian Klug
Julian Klug

🤔
David Völgyes
David Völgyes

🤔 💻
Jean-Christophe Fillion-Robin
Jean-Christophe Fillion-Robin

📖
Suraj Pai
Suraj Pai

🤔
Ben Darwin
Ben Darwin

🤔
Oeslle Lucena
Oeslle Lucena

🐛
Soumick Chatterjee
Soumick Chatterjee

💻
neuronflow
neuronflow

📖
Jan Witowski
Jan Witowski

📖
Derk Mus
Derk Mus

📖 💻 🐛
Christian Herz
Christian Herz

🐛
Cory Efird
Cory Efird

💻 🐛
Esteban Vaca C.
Esteban Vaca C.

🐛
Ray Phan
Ray Phan

🐛
Akis Linardos
Akis Linardos

🐛 💻
Nina Montana-Brown
Nina Montana-Brown

📖 🚇
fabien-brulport
fabien-brulport

🐛
malteekj
malteekj

🐛
Andres Diaz-Pinto
Andres Diaz-Pinto

🐛
Sarthak Pati
Sarthak Pati

📦 📖
GabriellaKamlish
GabriellaKamlish

🐛
Tyler Spears
Tyler Spears

🐛
DaGuT
DaGuT

📖
Xiangyu Zhao
Xiangyu Zhao

🐛
siahuat0727
siahuat0727

📖 🐛
Svdvoort
Svdvoort

💻
Albans98
Albans98

💻
Matthew T. Warkentin
Matthew T. Warkentin

💻
glupol
glupol

🐛
ramonemiliani93
ramonemiliani93

📖 🐛 💻
Justus Schock
Justus Schock

💻 🐛 🤔 👀
Stefan Milorad Radonjić
Stefan Milorad Radonjić

🐛
Sajan Gohil
Sajan Gohil

🐛
Ikko Ashimine
Ikko Ashimine

📖
laynr
laynr

📖
Omar U. Espejel
Omar U. Espejel

🔊
James Butler
James Butler

🐛
res191
res191

🔍
nengwp
nengwp

🐛 📖
susanveraclarke
susanveraclarke

🎨
nepersica
nepersica

🐛
Sebastian Penhouet
Sebastian Penhouet

🤔
Bigsealion
Bigsealion

🐛
Dženan Zukić
Dženan Zukić

👀
vasl12
vasl12

🐛
François Rousseau
François Rousseau

🐛
snavalm
snavalm

💻
Jacob Reinhold
Jacob Reinhold

💻
Hsu
Hsu

🐛
snipdome
snipdome

🐛
SmallY
SmallY

🐛
guigautier
guigautier

🤔
AyedSamy
AyedSamy

🐛
J. Miguel Valverde
J. Miguel Valverde

🤔 💻 🐛
José Guilherme Almeida
José Guilherme Almeida

🤔
Asim Usman
Asim Usman

🐛
cbri92
cbri92

🐛
Markus J. Ankenbrand
Markus J. Ankenbrand

🐛
Ziv Yaniv
Ziv Yaniv

📖
Luca Lumetti
Luca Lumetti

💻 📖
chagelo
chagelo

🐛
mueller-franzes
mueller-franzes

💻 🐛
Abdelwahab Kawafi
Abdelwahab Kawafi

🐛
Arthur Masson
Arthur Masson

🐛 📖
양현식
양현식

💻
nicoloesch
nicoloesch

💻 🐛
Amund Vedal
Amund Vedal

📖
Alabamagan
Alabamagan

🐛
sbdoherty
sbdoherty

📖
Zhack47
Zhack47

🐛
Blake Dewey
Blake Dewey

📖
Doyeon Kim
Doyeon Kim

🐛
KonoMaxi
KonoMaxi

🐛
Laurent Chauvin
Laurent Chauvin

🐛
Christian Hinge
Christian Hinge

🐛
zzz123xyz
zzz123xyz

🐛
Amin Alam
Amin Alam

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

torchio's People

Contributors

albans98 avatar allcontributors[bot] avatar aminalam avatar blakedewey avatar christianhinge avatar dagut avatar deepsource-autofix[bot] avatar deepsourcebot avatar dependabot[bot] avatar dmus avatar dvolgyes avatar efirdc avatar eltociear avatar fepegar avatar gfabien avatar ghilesreguig avatar haughty-yeon avatar jcreinhold avatar julianklug avatar justusschock avatar linardos avatar lucalumetti avatar mattwarkentin avatar nwschurink avatar pre-commit-ci[bot] avatar ramonemiliani93 avatar romainvala avatar sarthakpati avatar siahuat0727 avatar vedal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

torchio's Issues

Label image sampler

Hi fernando,

I recently switched from tf to pytorch and I was really happy to find your library.
Great work! Thanks.

  • I added a more efficient image sampler to sample random patches which should contain
    at least one point of a specific label.
    https://github.com/lab-midas/midas-torchio/blob/dev_tobias/torchio/data/sampler/label.py
    (code and examples are still a bit messy, I will work on this the next days).
    But maybe you can use (parts of) it ;)

  • There was also a minor issue if the patch size is equal to the image size in a dimension
    (missing +1, rand numbers low=a high=b -> sample from [a,b) so b can be the max_size). I corrected this.
    This is very helpful to use the patch sampler as a slice sampler (for instance slicing 512x512 from 512x512x156 volumes).

Cheers
Tobias

save_sample from ImagesDataset

When using the save_sample method from ImagesDataset
the nifti have a wrong dimention one should change

        tensor = sample[key]['data']

by

        tensor = sample[key]['data'].squeeze()

Not sure if this is the rigth place for this function, why not put it directly in io.py ?

Possibility to use external mask when masking function

For some Transform : histogram_standardization rescale z_normalization there may be an interest to use a mask (just to compute percentyl or min max values) then the transform is apply to the all images

This is possible with histogram_standardization (and we should add the option with rescale)

My point is that a masking_function is not an easy job, and I do prefer to use mask compute independently (with your prefered software)

In the case of external mask, you can easily use them by including then in the ImageDataset

suj = [[
    Image('T1','/oneT1.nii.gz',INTENSITY),
    Image('mask','/coresponding_mask.nii.gz',LABEL)
     ]]

Then you can use a parameter mask_field_name to get this mask when needed

here is an example of such an implementation
https://github.com/romainVala/torchio/blob/master/torchio/transforms/rescale_within_mask.py

but I thing it is better, to directly incorporate it as an optional feature of the Rescale class with something like

   if sefl.mask_field_name is not None :
       mask_data = sample[self.mask_field_name]['data']

About ZNormalization I would prefer to set use_mean_threshold to False by default and add the possiblity to use either a masking_function or the external mask

For histogram_standardization, a masking_function is expected, (but not use in the call), I added the possibility of external mask
https://github.com/romainVala/torchio/blob/master/torchio/transforms/histogram_standardization.py

of course those option are exclusive, and the user should set only one of them, I am not sure what the best way to code it properly, I did something like

    if masking_function is not None:
        mask = masking_function(img)
    else:
        if mask_data is not None:
            mask = mask_data
        else:
            mask = np.ones_like(img, dtype=np.bool)

Wrong intensity when RandomMotion is applied after ZNormalization

To reproduce:

from torchio import Image, ImagesDataset, INTENSITY
from torchio.transforms import (
    RandomAffine,
    RandomFlip,
    RandomNoise,
    RandomBiasField,
    RandomElasticDeformation,
    RandomMotion,
    ZNormalization,
)

paths_list = [[
    Image('image', '~/Dropbox/MRI/t1.nii.gz', INTENSITY),
]]

seed = None
verbose = True

transforms = [
    ZNormalization(verbose=verbose),
    RandomMotion(proportion_to_augment=1, seed=seed, verbose=verbose),
    # RandomNoise(seed=seed, verbose=verbose),
    # RandomBiasField(seed=seed, verbose=verbose),
    # RandomFlip(axes=(0,), seed=seed, verbose=verbose),
    # RandomAffine(seed=seed, verbose=verbose),
    # RandomElasticDeformation(proportion_to_augment=0.1, seed=seed, verbose=verbose),
]

dataset = ImagesDataset(paths_list)

sample = dataset[0]
for i, transform in enumerate(transforms):
    transformed = transform(sample)
    name = transform.__class__.__name__
    path = f'/tmp/{i}_{name}.nii.gz'
    dataset.save_sample(transformed, dict(image=path))

@romainVala do you know why this could be? I'm probably missing some theory about the Fourier transform.

write sfrom and qform

I notice that you set (in _write_nifti in io.py)

nii.header['sform_code'] = 0

It is more robust (for other software) to set both sform and qform. I would prefer to have

nii.header['sform_code'] = 1

this will save both sfrom and qform (to the same value)

errro in random_bias_field.py

Hello
I get the following error when I try to apply the bias_field

/data/romain/toolbox_python/torchio/torchio/transforms/random_bias_field.py in apply_transform(self, sample)
     34             bias_field = self.generate_bias_field_map(
     35                 image_dict['data'], self.order, coefficients)
---> 36             image_dict['data'] *= torch.from_numpy(bias_field)
     37         return sample
     38 

RuntimeError: unsupported operation: more than one element of the written-to tensor refers to a single memory location. Please clone() the tensor before performing the operation.

if I change the corresponding line with

            iii = image_dict['data'] * torch.from_numpy(bias_field)
            image_dict['data'] = iii

it pass,
very strange I do not understand why ...

understanding the input format

Hi there

Just a small issue in order to fully understand the input format logic
I see in torchio.py that you define 3 data type : Intensity, label and sampling_map
what is the implication of choosing one of those ?

Why in your example_multimodal.py do you define one_subject_dict with a 'label' which has type=torchio.INTENSITY ? (why not torchio.LABEL ?)

many thanks

Attempting to set a non-orthogonal rotation matrix

This happens sometimes. I need to figure out how to reproduce this error.

Exception thrown in SimpleITK Euler3DTransform_SetMatrix: /tmp/SimpleITK-build/ITK-prefix/include/ITK-4.13/itkRigid3DTransform.hxx:94:
itk::ERROR: Euler3DTransform(0x558bdd7a4780): Attempting to set a non-orthogonal rotation matrix

Add image padding

It can be useful to pad the images in the transform operations.
In particular, the current grid sampler ignore the borders of the full image, adding a padding of the size of the border could solve this problem (if consistent with training).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.