Hello all,
I am trying to use the LoG filter in Pyradiomics. I have been successful with the other filters using the enableImageTypeByName (imageType, enabled=True). But when I use ‘LoG’, I do not get the LoG results, just the original (no filter) ones. The output for the print(Enabled features) reports both original and LoG are enabled. No errors or issues are reported. But again, just the original (no filter) results are the output. Below is the code. Any help?
import os
from radiomics.featureextractor import RadiomicsFeatureExtractor
import SimpleITK as sitk
# Define paths to your image and mask
source = '/Users/alexflores/Desktop/Mrn_1/Mrn_1_source.nii.gz'
mask = '/Users/alexflores/Desktop/Mrn_1/Mrn_1_T1tmask.nii.gz'
# Load images
image = sitk.ReadImage(source)
mask_image = sitk.ReadImage(mask)
# Initialize the feature extractor
extractor = RadiomicsFeatureExtractor()
# Enable specific image types
try:
extractor.enableImageTypeByName('LoG', enabled=True)
except Exception as e:
print(f"Error enabling LoG image type: {e}")
# Print settings to confirm changes
print('Extraction parameters:\n\t', extractor.settings)
print('Enabled filters:\n\t', extractor.enabledImagetypes)
print('Enabled features:\n\t', extractor.enabledFeatures)
# Extract features from the image and mask
try:
result = extractor.execute(source, mask)
print('Result type:', type(result))
# Print calculated features
print('Calculated features:')
for key, value in result.items():
print('\t', key, ':', value)
except Exception as e:
print('An error occurred:', e)
# Convertfeaturevaluestonumpyarray
import numpy as np
import csv
# Define the CSV file path
csv_file_path = '/Users/alexflores/Desktop/features.csv'
# Open the CSV file for writing
with open(csv_file_path, mode='w', newline='') as file:
writer = csv.writer(file)
# Write the header (column names)
writer.writerow(['Feature', 'Value'])
# Write each feature and its value
for key, value in result.items():
# Handle dictionary values (convert to string)
if isinstance(value, dict):
value = str(value)
writer.writerow([key, value])
print(f"Data has been written to {csv_file_path}")