From 4ba2af3de85d038c3c35c50eb478d40033bd12ce Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 4 Aug 2022 23:46:36 -0400 Subject: [PATCH 1/2] added feature extraction --- feature_extraction.py | 25 +++++++++++++++++++++++++ requirements.txt | 13 +++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 feature_extraction.py create mode 100644 requirements.txt diff --git a/feature_extraction.py b/feature_extraction.py new file mode 100644 index 0000000..8dacc35 --- /dev/null +++ b/feature_extraction.py @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7404f59 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +docopt==0.6.2 +numpy==1.23.1 +pandas==1.4.3 +pydicom==2.3.0 +pykwalify==1.8.0 +pyradiomics==3.0.1 +python-dateutil==2.8.2 +pytz==2022.1 +PyWavelets==1.3.0 +ruamel.yaml==0.17.21 +ruamel.yaml.clib==0.2.6 +SimpleITK==2.1.1.2 +six==1.16.0 From 16193ddde37891812eaa29cb23d5269fe3393300 Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 4 Aug 2022 23:51:49 -0400 Subject: [PATCH 2/2] removed unnecessary imports --- requirements.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7404f59..07c2453 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,8 @@ docopt==0.6.2 numpy==1.23.1 -pandas==1.4.3 -pydicom==2.3.0 pykwalify==1.8.0 pyradiomics==3.0.1 python-dateutil==2.8.2 -pytz==2022.1 PyWavelets==1.3.0 ruamel.yaml==0.17.21 ruamel.yaml.clib==0.2.6