Giter Site home page Giter Site logo

fepegar / torchio Goto Github PK

View Code? Open in Web Editor NEW
2.0K 18.0 233.0 45.23 MB

Medical imaging toolkit for deep learning

Home Page: http://www.torchio.org

License: Apache License 2.0

Python 100.00%
pytorch medical-image-computing deep-learning data-augmentation medical-images machine-learning python medical-image-processing medical-image-analysis medical-imaging-datasets

torchio's Issues

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

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 ...

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

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).

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

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.