import numpy as np
import torchio as tio
from torch.utils.data import DataLoader
import torch
import nibabel as nib
z=0
while z<999:
z = z+1
subject = tio.Subject(
chest_ct=tio.ScalarImage(fr'C:\Users\Admin\Desktop\EGFR total\EGFRzhong\new\data1\data{z}.nii.gz'),
heart_mask=tio.LabelMap(fr'C:\Users\Admin\Desktop\EGFR total\EGFRzhong\new\mask1\mask{z}.nii.gz'),
)
subject.chest_ct.shape
transform = tio.CropOrPad(
# (96, 96, 96),
mask_name='heart_mask',
)
transformed = transform(subject)
transformed.chest_ct.shape
a = transformed.get_first_image()
a = a.numpy()
x = a[0]
print(a[0].shape)
img_t1 = nib.Nifti1Image(x, np.eye(4))
nib.save(img_t1, f'output{z}.nii.gz') # 将之保存为nii查看
医疗图像ROI区域根据标注自动提取
最新推荐文章于 2024-06-25 00:19:59 发布