python 将RTstruct文件保存为nii文件

背景
鄙人主要做医学图像配准,训练或测试模型时需要用到数据集中的金标准mask。一些机构提供RTstruct文件,我需要将其转为nii格式,以此来方便我运用。

方法
利用dcmrtstruct2nii 工具包
第一步:安装dcmrtstruct2nii 包

pip install dcmrtstruct2nii 

第二步:使用
官网介绍:
官网网址https://pypi.org/project/dcmrtstruct2nii/

# lets test it
from dcmrtstruct2nii import dcmrtstruct2nii, list_rt_structs

print(list_rt_structs('/path/to/dicom/rtstruct/file.dcm'))

dcmrtstruct2nii(rtstruct_file='/path/to/dicom/rtstruct/file.dcm', 
				dicom_file='/path/to/original/extracted/dicom/files',
 				output_path='/output/path')

输入说明
rtstruct_file=待转换的RTstruct文件的文件路径
dicom_file=RTstruct对应的医学dicom图像的文件夹路径
output_path=输出文件夹路径。

我的尝试以及结果:
我的python代码:

from dcmrtstruct2nii import dcmrtstruct2nii, list_rt_structs

root='E:\Medical imaging dataset/'
patient_Data='patient_001/07-06-2012/'
print(list_rt_structs(root+patient_Data+'1.000000-BSCBLLLRSDCB-27748/1-1.dcm'))
dcmrtstruct2nii(rtstruct_file=root+patient_Data+'1.000000-BSCBLLLRSDCB-27748/1-1.dcm',
                dicom_file=root+patient_Data+'201.000000-PANCREAS DI iDose 3-97846/',
                output_path=root+patient_Data+'1.000000-BSCBLLLRSDCB-27748/')

"""
输出如下:
['Bowel_sm_CBCT', 'LUNG_L', 'LUNG_R', 'Stomach_duo_CBCT']
代表该RTstruct文件,包含四个mask
"""

最终在output_path文件夹中得到5个nii文件

image.nii由dicom_file=root+patient_Data+'201.000000-PANCREAS DI iDose 3-97846/'中的dicom生成得到。
mask_XX.nii由rtstruct_file=root+patient_Data+'1.000000-BSCBLLLRSDCB-27748/1-1.dcm'RTstruct文件生成

猜你喜欢

转载自blog.csdn.net/qq_45384162/article/details/127672421