Automated PyRadiomics Feature work with DICOM and DICOM RT structure


I have already installed pyradiomics and Slicer RT via extension manager.

In the DICOM RT structure file, there are contour data for regions of interest (ROIs) [1]) of the tumor shape.
In the DICOM file, I have an MRI of the patient.
I searched for Radiomics in the 3d slicer’s module and ran it. I put the DICOM RT file in the “input regions” and the MR image in the “Input Image Volume”.
As shown in the image below, I was able to successfully extract the Radiomics Features from the MR image of the ROI (Tumor).

i need to do these operations multiple times. So I want to do these labor intensive things automatically.
Is it possible to automate this with python code?
For example, I have 100 RT structure (outlined tumor regions) DICOM files and 100 DICOM (MR brain) images, can I use code to automatically extract features in pyRadiomics & 3d slicer to do the work at once?

I tried to do this with the python code with Google colab & gpt4 (microsoft bing), but i failed to do it.

Here is the code:

"# Install necessary libraries
!pip install pydicom
!pip install pyradiomics
!pip install SimpleITK

Mount Google Drive

from google.colab import drive

Import libraries

import os
import pydicom
import SimpleITK as sitk
from radiomics import featureextractor
import six

Set file paths

dicom_dir = “/content/gdrive/MyDrive/MNG_Sample_001”
mask_file = os.path.join(dicom_dir, “RTSS.dcm”)

Load DICOM files

dicom_files = [os.path.join(dicom_dir, f) for f in os.listdir(dicom_dir) if f.startswith(‘IMG’) and f.endswith(‘.dcm’)]
dicom_files.sort(key=lambda x: int(x.split(‘IMG’)[-1].split(‘.dcm’)[0]))

Load DICOM image

reader = sitk.ImageSeriesReader()
image = reader.Execute()

Load DICOM RT Structure Set file as mask

mask = sitk.ReadImage(mask_file)

Set PyRadiomics parameters

params = {}
params[‘binWidth’] = 25
params[‘resampledPixelSpacing’] = None
params[‘interpolator’] = ‘sitkBSpline’
params[‘enableCExtensions’] = True

extractor = featureextractor.RadiomicsFeatureExtractor(**params)

Extract features

result = extractor.execute(image, mask)

Print results

for key, val in six.iteritems(result):
print(“\t%s: %s” % (key, val))

[1] Create and Display 3-D Mask of DICOM-RT Contour Data - MATLAB & Simulink - MathWorks 한국