Different image_interpolation
arguments for each element of a dictionary input
#421
-
Hi! I'm new to TorchIO so forgive me if I miss any obvious and already clarified point. I wish to use the
I wish to use a different interpolation method for different inputs (e.g., 'linear' for 'data' and 'nearest' for 'label'). After a couple of clicks, I found that the only way to do so is to create a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hi, @stalhabukhari. It's a legit question and you're right, that's the only way for now. If there is interest, we can add support to pass a dictionary of interpolations. That will also improve compatibility with related libraries. I could work on this next month. Ouf of curiosity, why don't you use In [1]: import torchio as tio
In [2]: colin = tio.datasets.Colin27()
In [3]: isinstance(colin, dict)
Out[3]: True |
Beta Was this translation helpful? Give feedback.
-
Ok, I think I was right to suspect that you don't need a input_subj = torchio.Subject({'data': torchio.ScalarImage(tensor=data_volume), 'label': torchio.LabelMap(tensor=label_volume)})
# Alternative syntax
input_subj = torchio.Subject(data=torchio.ScalarImage(tensor=data_volume), label=torchio.LabelMap(tensor=label_volume))
fn = torchio.transforms.RandomAffine()
output_subj = fn(input_subj) you will have applied the same transform to both images. The resampling is nearest neighbor for label maps, and linear by default for everything else. And the transform is applied to all images by default, so you don't need In [1]: import torchio as tio
In [2]: colin = tio.datasets.Colin27()
In [3]: colin.t1
Out[3]: ScalarImage(path: "/home/fernando/.cache/torchio/mni_colin27_1998_nifti/colin27_t1_tal_lin.nii")
In [5]: colin.brain
Out[5]: LabelMap(path: "/home/fernando/.cache/torchio/mni_colin27_1998_nifti/colin27_t1_tal_lin_mask.nii")
In [6]: colin.plot() In [7]: transform = tio.RandomAffine()
In [8]: transformed = transform(colin)
In [9]: transformed.plot() |
Beta Was this translation helpful? Give feedback.
-
Awesome! |
Beta Was this translation helpful? Give feedback.
Ok, I think I was right to suspect that you don't need a
dict
at all. If you run:you will have applied the same transform to both images. The resampling is nearest neighbor for label maps, and linear by default for everything else. And the transform is applied to all images by default, so you don't need
include
at all.Basically, you don't need to specify a…