# Automated PyRadiomics Feature work with DICOM and DICOM RT structure

**URL:** <https://discourse.slicer.org/t/automated-pyradiomics-feature-work-with-dicom-and-dicom-rt-structure/36829>\
**Category:** Radiomics\
**Created:** [June 17, 2024, 2:35am UTC](https://discourse.slicer.org/t/automated-pyradiomics-feature-work-with-dicom-and-dicom-rt-structure/36829 "2024-06-17T02:35:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![youngchanseo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/youngchanseo/32/76597_2.png) [@youngchanseo](https://discourse.slicer.org/u/youngchanseo)\
**Post date:** [June 17, 2024, 2:35am UTC](https://discourse.slicer.org/t/automated-pyradiomics-feature-work-with-dicom-and-dicom-rt-structure/36829/1 "2024-06-17T02:35:22Z")

</div>

Hello.

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).

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/8/e8d505b29f3e7f83e19ddacd274c81a6b0d3a287.jpeg)

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?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/9/193710cbbe9342f360ea7963dc4a0d2db99a9419.png)

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  
drive.mount(‘/content/gdrive’)

# 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()  
reader.SetFileNames(dicom\_files)  
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 한국](https://kr.mathworks.com/help/images/create-and-display-3-d-mask-of-dicom-rt-contour-data.html)
