Commit a9647f17 authored by Alessia Marcolini's avatar Alessia Marcolini
Browse files

Extraction of intensity features depending on the modality

parent e2c4fea3
......@@ -15,10 +15,12 @@ warnings.filterwarnings("ignore")
# %%
# os.chdir('..')
DATASET = Path('HN_val')
BBOX = 'bbox_64'
DATASET = Path('HN_BZ')
BBOX = 'bbox_64_rad'
VOXEL_SPACING = (1.0, 1.0, 1.0)
SCAN_NAMES = ['CT', 'PT'] # you are lucky that CT scans are the first in the stack
SCAN_NAMES = ['CT', 'PT']
CT_index = SCAN_NAMES.index('CT')
PT_index = SCAN_NAMES.index('PT')
N_JOBS = 32
N_BINS = [8, 16, 32, 64]
......@@ -34,13 +36,16 @@ clinical = pd.read_csv(Path('data') / DATASET / 'processed' / f'clinical_{DATASE
params_shape = '02_radiomics_features_extraction/shape_new.yaml' # param file to use to create the extractor
extractor_shape = RadiomicsFeatureExtractor(params_shape)
params_intensity = '02_radiomics_features_extraction/intensity.yaml' # param file to use to create the extractor
extractor_intensity = RadiomicsFeatureExtractor(params_intensity)
params_intensity_CT = '02_radiomics_features_extraction/intensity_CT.yaml' # param file to use to create the extractor
extractor_intensity_CT = RadiomicsFeatureExtractor(params_intensity_CT)
params_intensity_PET = '02_radiomics_features_extraction/intensity_PET.yaml' # param file to use to create the extractor
extractor_intensity_PET = RadiomicsFeatureExtractor(params_intensity_PET)
params_texture = '02_radiomics_features_extraction/texture_new.yaml' # param file to use to create the extractor
extractor_texture = RadiomicsFeatureExtractor(params_texture)
filenames = [f for f in os.listdir(DATADIR) if f.endswith('.npy')]
filenames = [f for f in os.listdir(DATADIR) if f.endswith('.npy')][:2]
exclude_list = []
......@@ -60,22 +65,31 @@ def process_file(filename):
curr_modality.SetSpacing(VOXEL_SPACING)
modalities.append(curr_modality)
has_label = np.max(data[-1, :, :, :]) > 0
has_label = np.max(data[-1, :, :, :]) > 0 #### fix
if has_label:
segmentation = sitk.GetImageFromArray(data[-1, :, :, :].astype(np.uint8))
segmentation.SetSpacing(VOXEL_SPACING)
feature = {}
# shape features
result = extractor_shape.execute(modalities[0], segmentation)
# shape features only for CT
result = extractor_shape.execute(modalities[CT_index], segmentation)
for key, value in result.items():
if not key.startswith("general_"):
feature[key] = result[key]
feature[f'{key}_{SCAN_NAMES[CT_index]}'] = result[key]
for modality, name in zip(modalities, SCAN_NAMES):
# intensity features
result = extractor_intensity.execute(modality, segmentation)
if name == 'CT':
extractor = extractor_intensity_CT
elif name == 'PT':
extractor = extractor_intensity_PET
else:
raise ValueError(
f'No intensity extractor defined for {name} modality!'
)
result = extractor.execute(modality, segmentation)
for key, value in result.items():
if not key.startswith("general_"):
feature[f'{key}_{name}'] = result[key]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment