qurit / rt-utils

A minimal Python library to facilitate the creation and manipulation of DICOM RTStructs.
MIT License
195 stars 57 forks source link

File type for ML masks #83

Closed MattAWard closed 1 year ago

MattAWard commented 1 year ago

What file type/ format are the masks expected to be in to create the RTStruct files? We're currently trialling a ML auto segmentation solution which outputs anatomical models as separate nii.gz (zipped nifti) files. Do you know if files of this type can be converted into the required format for them to be packaged into an RTStruct file? Thanks.

sunyu0410 commented 1 year ago

@MattAWard As long as you can convert the NIfTI file into a numpy array, then you can incorporate that using rt-utils. You can use nibabel to read a nii.gz and get the numpy array.

import nibabel as nib

nii = nib.load('path/to/.nii.gz')
arr = nii.get_fdata()
danihinjos commented 1 year ago

Hi! How do you exactly convert a NifTI file in numpy array into a RTStruct? It's unclear :/

MattAWard commented 1 year ago

Thanks @sunyu0410 and that bit isn't too bad @danihinjos you just do

rtstruct.add_roi(mask=arr, name=roi_name) rtstruct.save(destination_folder)

I have a loop in my Python code that adds ROIs recursively then saves the rtstruct