Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added feature extraction #15

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions feature_extraction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import numpy as np
import os
import radiomics
import SimpleITK as sitk

from radiomics import featureextractor

def extract_features_from_images(segmented_image_path, raw_image_path):
results = {}

extractor = featureextractor.RadiomicsFeatureExtractor()
extractor.enableAllFeatures()

for segmented_file in os.listdir(segmented_image_path):
raw_image = sitk.ReadImage(os.path.join(raw_image_path, segmented_file.replace('segmented_', '')),
sitk.sitkUInt8)
raw_image_arr = sitk.GetArrayFromImage(raw_image)
segmented_image = sitk.ReadImage(os.path.join(segmented_image_path, segmented_file),
sitk.sitkUInt8)

mask_arr = sitk.GetArrayFromImage(segmented_image)
# mask_arr[0][0] gets the label for the mask
featureVector = extractor.execute(raw_image, segmented_image, label=int(mask_arr[0][0]))
results[segmented_file] = np.array([(feature, value) for feature, value in featureVector.items()], dtype=object)
return results
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
docopt==0.6.2
numpy==1.23.1
pykwalify==1.8.0
pyradiomics==3.0.1
python-dateutil==2.8.2
PyWavelets==1.3.0
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.6
SimpleITK==2.1.1.2
six==1.16.0