question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update RandomLabelsToImage

See original GitHub issue

@GFabien @romainVala

Now that I’ve included the ICBM template, do you think it’s a good idea to simplify a bit the example in RandomLabelsToImage? Also, Colin27 2008 is very large.

For example:

import torchio
from torchio import RandomLabelsToImage
from torchio.datasets import ICBM2009CNonlinearSymmetryc

icbm = ICBM2009CNonlinearSymmetryc(load_4d_tissues=False)

# Default Gaussian parameters
transform = RandomLabelsToImage(
    pv_label_keys=['gm', 'wm', 'csf'],
)
transformed = transform(icbm)
transformed['image'].save('/tmp/lab2im.nii')

# Specify Gaussian parameters
gaussian_parameters = {
    'gm': dict(mean=2, std=0.1),
    'wm': dict(mean=4, std=0.1),
    'csf': dict(mean=6, std=0.1),
}
transform = RandomLabelsToImage(
    pv_label_keys=['gm', 'wm', 'csf'],
    gaussian_parameters=gaussian_parameters,
)
transformed = transform(icbm)
transformed['image'].save('/tmp/lab2im.nii')

lab2im

I can also add an option in the ICBM class to create a label map from the PV images.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
GFabiencommented, Aug 6, 2020

Why not, however it means that you have to specify every mean and std (even when you specify that a tissue will not be used because it will be directly taken from the original image).

1reaction
fepegarcommented, Aug 6, 2020

That would be the best solution and it would make it transparent to the transform. If this seems good to you I’ll make a PR to refactor RandomLabelsToImage to handle only single label map (be it a PV label map or not) and enable Image to take a list of paths.

Sounds good thanks! I think an if isinstance(path, list) and torch.cat(tensors) in Image.load() would do. Maybe also asserting that all affines are the same. This could be extended to Image.save() (taking a path per channel).

What I’m not sure about however is if I should make a clear distinction between PV and label maps. Indeed, you could find if you’re facing a label map by rounding the tensor and compare it to itself but with datasets such as Colin27 2008 you can be surprised. Furthermore, label maps can now be given as one hot encoded label maps so you should take the argmax to get a usual label map. Maybe the discretize attribute is enough to make this distinction clear.

I guess you’re right. At the end of the day, they are just soft or hard assignments, in 4D volumes, that can sometimes be summarized in a 3D volume. However, the Colin27 2008 is an outlier, their volume is clearly wrong (I email the maintainer, no reply).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set random labels for images in tf.data.Dataset - Stack Overflow
What I would like to do is change each of these labels to a random number from 0 to 3. My code is...
Read more >
Need Help on Image Label Randomly Changing
Hello. I'm trying to make this image label where it randomly changes airline logos. The problem is that it only works once and...
Read more >
What Do Neural Networks Learn When Trained With Random ...
We study deep neural networks (DNNs) trained on natural image data with entirely random labels. Despite its popularity in the literature, where ...
Read more >
Set up image labeling project - Azure Machine Learning
Learn how to create and run data labeling projects to label images in Azure Machine Learning. Use machine-learning-assisted data labeling, ...
Read more >
randomPatchExtractionDatastore - MathWorks
Create a random patch extraction datastore to extract random patches of size 32-by-32 pixels from the images and corresponding pixel labels. Set the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found