Python saves RTstruct file as nii file

Background :
I mainly do medical image registration, and the gold standard mask in the data set is needed when training or testing the model. Some organizations provide RTstruct files, and I need to convert them to nii format for my convenience.

Method :
Use the dcmrtstruct2nii toolkit
Step 1 : Install the dcmrtstruct2nii package

pip install dcmrtstruct2nii 

Step 2 : Use
Official website introduction:
Official website URL 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')

Input
rtstruct_file=the file path of the RTstruct file to be converted
dicom_file=The folder path of the medical dicom image corresponding to the RTstruct
output_path=Output folder path.

My attempts and results:
my python code:

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
"""

In the end, output_path5 nii files

image.nii are generated dicom_file=root+patient_Data+'201.000000-PANCREAS DI iDose 3-97846/'by dicom in the folder.
mask_XX.nii rtstruct_file=root+patient_Data+'1.000000-BSCBLLLRSDCB-27748/1-1.dcm'is generated from RTstruct file

Guess you like

Origin blog.csdn.net/qq_45384162/article/details/127672421