diameter_dict={}
with open('/xunlian/annotations.csv' ,‘r’) as f:
for row in list(csv.reader(f)[1:]):
series_uid = row[0]
annotationCenter_xyz = tuple([float(x) for x in row[1:4]])
annotationDiameter_mm = float(row[4])
diameter_dict.setdefault(series_uid,[]).append(annotationCenter_xyz ,annotationDiameter_mm )
#两个文件存储的中心点坐标距离相差是否超过了结节直径的四分之一
candidateInfo_list.sort(reverse=True)
return candidateInfo_list
# 导入SimpleITK
import SimpleITK as sitk
class Ct:
def _init_(self,series_uid):
mhd_path = glob.glob('/xunlian/subset*/{}.mhd'.format(series_uid))[0]
ct_mhd = sitk.ReadImage(mhd_path)
ct_a = np.array(sitk.GetArrayFromImage(ct_mhd),dtype=np.float32
ct_a.clip(-1000,1000,ct_a)
self.series_uid = series_uid
self.hu_a = ct_a # HU
self.origin_xyz = XyzTuple(*ct_mhd.GetOrigin())
self.vxSize_xyz = XyzTuple(*ct_mhd.GetSpacing())
self.direction_a = np.array(ct_mhd.GetDirection().reshape(3,3))
# 毫米为单位的坐标称为 (X,Y,Z)坐标,以体素为单位的坐标称为(I,R,C)
数据坐标系的转化的代码实现
IrcTuple = collections.namedtuple('IrcTuple',['index','row','col'])
XyzTuple = collections.namedtuple('XyzTuple',['x','y','z'])