Mismatch between the transformed image and the label #793
Unanswered
wenwenzhang18
asked this question in
Q&A
Replies: 3 comments 4 replies
-
Can you please share the data and a minimal working example to reproduce this issue? |
Beta Was this translation helpful? Give feedback.
0 replies
-
testData.zip |
Beta Was this translation helpful? Give feedback.
1 reply
-
import torch
import torchio as tio
from torch.utils.data import DataLoader
import SimpleITK as itk
subject_a = tio.Subject(
t1=tio.ScalarImage(r'E:\Data\Anatomy\mhd\T1\TrainData\T1_1.mhd'),
label = tio.LabelMap(r'E:\Data\Anatomy\mhd\T1\TrainData\MaskT1_1.mhd'),
label2 = tio.LabelMap(r'E:\Data\Anatomy\mhd\T1\TrainData\MaskT1_1.mhd')
)
subjects_list = [subject_a]
rescale = tio.RescaleIntensity(out_min_max=(0, 1))
spatial = tio.OneOf({
tio.RandomAffine(
scales=(0.5,2),
degrees=(10, 10, 10)):1,
tio.RandomElasticDeformation(
num_control_points=(20,20,20),
max_displacement=10,
locked_borders=2): 0,
tio.RandomBlur():0,
tio.RandomMotion():0,
#tio.BiasField():1,
#tio.RandomSwap(200,2):1
tio.RandomLabelsToImage():0
},
)
transforms = [rescale, spatial]
transform = tio.Compose(transforms)
# SubjectsDataset is a subclass of torch.data.utils.Dataset
subjects_dataset = tio.SubjectsDataset(subjects_list, transform=transform)
a_tranform = subjects_dataset[0]["t1"]["data"]
a_mask_tranform = subjects_dataset[0]["label"]["data"]
a_Tran = a_tranform.numpy()[0]
a_mask_Tran = a_mask_tranform.numpy()[0]
a_img = itk.GetImageFromArray(a_Tran.transpose(2,1,0))
a_mask_img = itk.GetImageFromArray(a_mask_Tran.transpose(2,1,0))
a_img.SetSpacing([0.80000001192092896,0.9375,0.9375])
a_mask_img.SetSpacing([0.80000001192092896,0.9375,0.9375])
itk.WriteImage(a_img,r"C:\a_img.mhd")
itk.WriteImage(a_mask_img,r"C:\a_mask_img.mhd")
##############
a_mask2_tranform = subjects_dataset[0]["label2"]["data"]
a_mask2_Tran = a_mask2_tranform.numpy()[0]
a_mask2_img = itk.GetImageFromArray(a_mask2_Tran.transpose(2,1,0))
a_mask2_img.SetSpacing([0.80000001192092896,0.9375,0.9375])
itk.WriteImage(a_mask2_img,r"C:\a_mask2_img.mhd") |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When elastic transformation or affine transformation is performed on the image and label at the same time, there is a mismatch between the transformed image and the label.
@fepegar
Beta Was this translation helpful? Give feedback.
All reactions