本笔记来源于B站Up主: 有Li 的影像组学的系列教学视频
本节(28)主要讲解: 用SimpleITK包进行ROI/病灶体积的计算
1、加载包
import SimpleITK as sitk
import numpy as np
2、将文件读入程序中
maskFilePath = "C:/Users/RONG/Desktop/ROI_calculation/lung1_label.nrrd"
reader = sitk.ImageFileReader()
reader.SetFileName(maskFilePath)
mask = reader.Execute()
3、计算ROI体积
maskArr = sitk.GetArrayFromImage(mask) # order:z, y, x
counts = np.sum(maskArr == 1)
print(counts)
spacing = mask.GetSpacing() #order: x, y, z
print(spacing)
unitVol = np.prod(spacing)
print(unitVol)
roiVol = unitVol * counts
print(roiVol)
4、本例结果
# 837
# (0.5703125, 0.5703125, 5.0)
# 1.62628173828125
# 1361.1978149414062