You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, author! The IXI dataset you processed is in .pkl format. Has it been converted to .pkl after operations such as skull stripping? Can this format be converted back to .nii.gz format?Thank you very much!
Also,I don't quite understand the data[0] here. Doesn't val_dataloader only provide one data? What are data[0][1][2][3] respectively.
'''
Validation
'''
eval_dsc = AverageMeter()
with torch.no_grad():
for data in val_loader:
model.eval()
data = [t.cuda() for t in data]
x = data[0]
y = data[1]
x_seg = data[2]
y_seg = data[3]
# x = x.squeeze(0).permute(1, 0, 2, 3)
# y = y.squeeze(0).permute(1, 0, 2, 3)
Hello, author! The IXI dataset you processed is in .pkl format. Has it been converted to .pkl after operations such as skull stripping? Can this format be converted back to .nii.gz format?Thank you very much!
Also,I don't quite understand the data[0] here. Doesn't val_dataloader only provide one data? What are data[0][1][2][3] respectively.
'''
Validation
'''
eval_dsc = AverageMeter()
with torch.no_grad():
for data in val_loader:
model.eval()
data = [t.cuda() for t in data]
x = data[0]
y = data[1]
x_seg = data[2]
y_seg = data[3]
# x = x.squeeze(0).permute(1, 0, 2, 3)
# y = y.squeeze(0).permute(1, 0, 2, 3)
'''
nii转pkl
'''
读取.nii文件
nii_file = 'data/LPBA40/test/S01.delineation.skullstripped.nii.gz'
img = nib.load(nii_file)
获取图像数据
img_data = img.get_fdata()
img_affine = img.affine # 获取affine矩阵
序列化到.pkl文件
with open('data/LPBA40/output.pkl', 'wb') as f:
pickle.dump(img_data, f)
I tried to convert the nii file to pkl, but pkl to nii failed.
'''
pkl转nii
'''
with open('data/LPBA40/output.pkl', 'rb') as f:
loaded_data = pickle.load(f)
print(loaded_data) # 查看加载的数据结构
从.pkl文件反序列化图像数据和affine矩阵
with open('data/LPBA40/output.pkl', 'rb') as f:
img_data, affine = pickle.load(f) # 同时加载图像数据和affine矩阵
创建一个新的Nifti1Image,使用加载的affine矩阵
new_img = nib.Nifti1Image(img_data, affine=affine)
保存为.nii文件
new_img_file = 'data/LPBA40/restored_image.nii.gz'
new_img.to_filename(new_img_file)
The text was updated successfully, but these errors were encountered: