背景:
一些医学图像提供的金标准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文件生成