Working with a dataset with different volumes
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Problem summary
I am working with BraTS 2021 dataset and I am not using patch-based training. The issue appears because I am feeding the model with volumes that have different heights and widths.
One solution is to use Resize. However, it causes deformation.
I tried using Resample to resample all the volumes in the dataset to one reference space. However, when plotting the results after resampling, it seems that the resampled volumes are also deformed.
given the code below,
Q1: did I do something wrong? Q2: is there a more robust way for unifying the height and width for all volumes?
PS: in the given code, I used two volumes with the same height and width to study the effect on the resulting shape.
Code for reproduction
import torchio as tio
import matplotlib.pyplot as plt
train_dir = "path"
train_set = tio.datasets.RSNAMICCAI(train_dir, train=True)
# size of volume0 is (1, 512, 512, 400) and volume1 is (1, 512, 512, 129)
resample_transform = tio.Resample((train_set[1]['FLAIR'].spatial_shape, train_set[1]['FLAIR'].affine))
transformed = resample_transform(train_set[0]['FLAIR'])
# size after resampling is (1, 512, 512, 129) for both volumes as expected
plt.figure("Before resampling")
plt.imshow(train_set[0]['FLAIR'].data[0, :, :, 200], aspect="auto")
plt.show()
plt.figure("After resampling")
plt.imshow(transformed.data[0, :, :, 65], aspect="auto")
plt.show()
# the slices are completely deformed
Actual outcome
the resampled slices are deformed
Error messages
No response
Expected outcome
I was expecting the the resampled volumes to have the same spatial structure but with lower resolution.
System info
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
I can not be sure, because I do not have the data, (strange, I just get the BraTS2021_Training_Data.tar with 1251 subject, but they are all at the same size, so I guess we do not have the same data …)
But from the dimension your first volume has 400 slices, you reslice it to 129 slices, so it makes sense that the z projection is changed … (but there is no deformation of the volume)
I advise you save the volume after resample (transformed.FLAIR.save(‘xx.nii’) ) and visualize it in a 3D viewer (itksnap, 3D slicer, fslview, mrview …) you will better understand what the resample do
I will try that. Thanks a lot for the support.