from torch.utils.data import Dataset, DataLoader
import numpy as np
import SimpleITK as sitk
import os
class My_MR_Dataset(Dataset):
"""
下载数据、初始化数据,都可以在这里完成
"""
def __init__(self, src_folder, params):
self.params = params
self.src_folder = src_folder
self.loadTrainingData()
self.images_numpy = self.getNumpyImages()
self.gt_numpy = self.getNumpyGt()
assert len(self.images_numpy) == len(self.gt_numpy)
self.len = len(self.images_numpy)
def __getitem__(self, index):
return self.images_numpy[list(self.images_numpy.keys())[index]], self.gt_numpy[list(self.gt_numpy.keys())[index]]
def __len__(self):
return self.len
def get_new_spacing(self, sitkImage, new_size):
center = np.array(sitkImage.GetOrigin())
old_size = np.array(sitkImage.GetSize())
old_spacing = np.array(sitkImage.GetSpacing())
new_size[-1] = old_size[-1]
x_rate = 0.45
y_rate = 0.45
old_size[0] = old_size[0] * x_rate
old_size[1] = old_size[1] * y_rate
new_spacing = ((old_size * old_spacing + center) - center) / new_size
new_spacing[-1] = old_spacing[-</
读取MR图像为torch.Tensor格式
最新推荐文章于 2024-04-28 15:30:42 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)