Code Monkey home page Code Monkey logo

Comments (4)

romainVala avatar romainVala commented on August 26, 2024 1

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.

romainVala avatar romainVala commented on August 26, 2024

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.

mueller-franzes avatar mueller-franzes commented on August 26, 2024

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.

fepegar avatar fepegar commented on August 26, 2024

Thank you both. I've added a warning in

from torchio.

Related Issues (20)

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.