def get_labels(contours, shape, slices):
z = [np.around(s.ImagePositionPatient[2], 1) for s in slices]
pos_r = slices[0].ImagePositionPatient[1]
spacing_r = slices[0].PixelSpacing[1]
pos_c = slices[0].ImagePositionPatient[0]
spacing_c = slices[0].PixelSpacing[0]
label_map = np.zeros(shape, dtype=np.float32)
for con in contours:
num = ROI_ORDER.index(con['name']) + 1
for c in con['contours']:
nodes = np.array(c).reshape((-1, 3))
assert np.amax(np.abs(np.diff(nodes[:, 2]))) == 0
z_index = z.index(np.around(nodes[0, 2], 1))
r = (nodes[:, 1] - pos_r) / spacing_r
c = (nodes[:, 0] - pos_c) / spacing_c
rr, cc = polygon(r, c)
label_map[z_index, rr, cc] = num
return label_map
评论列表
文章目录