How to Perform Radiomics Feature Extraction

Code

import radiomics
from radiomics import featureextractor
import pandas as pd

# Set the root directory where data is stored
dataDir = 'your_path/data/mri/'

# List of folders to process (typically corresponding to different patient IDs)
folderList = ['0001', '0002', '0003']

# Initialize the feature extractor
extractor = featureextractor.RadiomicsFeatureExtractor()

# Create an empty DataFrame to store all results
df = pd.DataFrame()

for folder in folderList:
    # Construct paths for the image (in .nii format) and the mask (i.e., the region manually delineated by a physician)
    imageName = dataDir + folder + '/data.nii'
    maskName = dataDir + folder + '/mask.nii.gz'
    
    # Perform feature extraction, returning an ordered dictionary
    featureVector = extractor.execute(imageName, maskName)
    
    # Convert the extracted feature vector into DataFrame format
    # .values() retrieves the values and transposes them; .keys() retrieves feature names as column headers
    df_add = pd.DataFrame.from_dict(featureVector.values()).T
    df_add.columns = featureVector.keys()
    
    # Append the current patient's features to the master table
    df = pd.concat([df, df_add])

# Save the final consolidated feature results as an Excel file
df.to_excel(dataDir + 'results.xlsx')

Extension

[Solved] Error installing pyradiomics on Python 3.10 or later: “This error likely indicates that you need to install a library that provides ‘cmatrices.h’” for pyradiomics@3.0.1a1 - :hammer_and_wrench: Tools & Programming - Beginner Forum

References

Radiomics Q&A: Understanding Python-based Feature Extraction Better — Bilibili