Comments (4)
ok I see,
handling it automatically is not obvious, because the padding value for the label may change given the use case, I think it should be handle by the user. But may be a warning when non integer label are created by pad is a good idea (or when the padding_mode=mean option is used)
A solution is to add 2 CropOrPad transform with include
argument
transformation = tio.Compose([
tio.RandomNoise(), # Correct, affects only 'image'
tio.CropOrPad((256,256,32), padding_mode='mean', include='image') #to apply only to image
tio.CropOrPad((256,256,32), padding_mode=0, include='label') #to apply only to label
])
adding an explicit argument like paddin_mode_label
, would be also a solution (... todo ...)
from torchio.
Hello
may be I do not understand your point, but for me, the outcome you get is directly due to the choice of padding_mode='mean'
(why using the mean for a label map ?)
For label, the best is to pad with the background label, usually 0 (which is the default if you do not specify the padding_mode
option)
if you want the padded valu to be equal to 5 just use
padding_mode=5
from torchio.
Hi
maybe my example was a bit misleading because it was too simplified. The actual use case is a preprocessing pipeline that applies CropOrPad to a subject containing a ScalarImage and a LabelMap. While transformations like RandomNoise are automatically applied to the ScalaImage only, CropOrPad "destroys" the LabelMap. It is not a bug but it seemed to me at least not intuitive, compared to the other transformations.
Example:
import torchio as tio
label = tio.LabelMap('path/to/label.nii')
image = tio.ScalarImage('path/to/image.nii')
subject = tio.Subject(image=image, label=label)
transformation = tio.Compose([
tio.RandomNoise(), # Correct, affects only 'image'
tio.CropOrPad((256,256,32), padding_mode='mean') # Correct for 'image', wrong for 'label'
])
label_trans = transformation(subject)
from torchio.
Thank you both. I've added a warning in
from torchio.
Related Issues (20)
- Suggestions the modifying default value of prefetch_factor and the argument to set it for minimize the blocking-bottleneck between fetch subject and generate patch in Queue HOT 1
- Different transforms applied to CT and label HOT 11
- The Affine matrix does not change after applying the augmentations HOT 3
- Custom loader not used when loading data lazily HOT 2
- Seed is not working HOT 2
- Silenced exception makes it harder to debug custom Transforms HOT 5
- Resample
- tio.Resample does not work with custom image class HOT 2
- Setting NUM_SAMPLES when using sampler with Queue HOT 3
- RescaleIntensity - multiple calls HOT 9
- Return sampled parameters upon request HOT 3
- Halve queue length when using DDP HOT 2
- bug in rotation part of tio.transforms.RandomAffine HOT 4
- get_subjects_from_batch has a hick-up with int metadata HOT 5
- masking_method in Mask class is not saved as argument (preventing applying the inverse transform)
- RandomAffine raises an error when isotropic=True and 3 elements are given for scales HOT 10
- Queue is not respecting the batch size HOT 1
- Resample an image by providing only the target affine HOT 1
- Supporting PyTorch 2.3 HOT 17
- Cannot copy subclass of Subject with keyword arguments HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torchio.