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.

Support 4D tensors as torchio.Image

See original GitHub issue

🚀 Feature

Make torchio accept 4D tensors (i.e. volumes with multiple channels) as input data for torchio.Image.

Motivation

I am working on a segmentation task using partial volume maps. Therefore, to take into account different tissues I need different channels as different tissues cannot be encoded to different integers.

Pitch

If a 3D tensor is given, torchio’s behaviour remains the same as before: the tensor is expanded to become a 4D tensor with a single channel. If a 4D tensor is given, it is directly loaded as it is. However, if there is a parameter saying that channels are at the end but should be at the beginning, dimensions are permuted so that we get channels first.

Alternatives

For now, the solution using torchio is to have several files and to create different attributes in the subject and concatenate these different maps on the channel dimension when I need to use them.

Additional context

I’m fine with the alternative solution but I fear that it could be inefficient if there are more than 10 channels and you have to apply a spatial transform independently on all these channels compared to applying the spatial transform on the 4D tensor. I’m not sure what would be the implications on the different transforms to handle 4D tensors with multiple channels (especially intensity transforms). Maybe only label type image should be allowed to be 4D.

I guess @fepegar you know better the pros and cons and why the choice was made to handle only 3D tensors in the first place.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fepegarcommented, Jul 1, 2020

I’ll close this for now. We can reopen if we ever consider this to be necessary.

0reactions
fepegarcommented, Jul 7, 2020

And for more completeness, here’s the affine from https://github.com/fepegar/torchio/issues/213#issuecomment-652304652 using the DGX:

Figure_1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add support for 4D images · Issue #238 · fepegar/torchio
Add support to read, write, sample and transform 4D images. Motivation. It would be convenient to support 4D images out of the box,...
Read more >
Image - TorchIO - Read the Docs
The Image class, representing one medical image, stores a 4D tensor, whose voxels encode, e.g., signal intensity or segmentation labels, ...
Read more >
Save Pytorch 4D tensor as image - python - Stack Overflow
In PyTorch this snippet is working and saving the image: from torchvision.utils import save_image import torch import torchvision tensor= ...
Read more >
TorchIO: A Python library for efficient loading ... - arXiv
The Image class, representing one medical image, stores a 4D tensor, whose voxels encode, e.g., signal intensity or segmentation labels, and the.
Read more >
Issue applying mask transform to 4d tensor · Discussion #893 ...
I guess this issue is somewhat related to a previous issue "Support 4D tensors as torchio.Image #213 ", but I was wondering if...
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