Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: 2

sphinx:
# Path to Sphinx configuration file.
configuration: docs/conf.py

# Set the version of Python
build:
os: ubuntu-20.04
Expand Down
File renamed without changes.
File renamed without changes.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import ray
from tqdm import trange

import MEDimage
import MEDiml


class BatchExtractorTexturalFilters(object):
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(
def __load_and_process_params(self) -> Dict:
"""Load and process the computing & batch parameters from JSON file"""
# Load json parameters
im_params = MEDimage.utils.json_utils.load_json(self._path_params)
im_params = MEDiml.utils.json_utils.load_json(self._path_params)

# Update class attributes
self.roi_types.extend(im_params['roi_types'])
Expand All @@ -95,7 +95,7 @@ def __compute_radiomics_one_patient(
Computes all radiomics features (Texture & Non-texture) for one patient/scan

Args:
name_patient(str): scan or patient full name. It has to respect the MEDimage naming convention:
name_patient(str): scan or patient full name. It has to respect the MEDiml naming convention:
PatientID__ImagingScanName.ImagingModality.npy
roi_name(str): name of the ROI that will be used in computation.
im_params(Dict): Dict of parameters/settings that will be used in the processing and computation.
Expand Down Expand Up @@ -136,7 +136,7 @@ def __compute_radiomics_one_patient(
# Load MEDscan instance
try:
with open(self._path_read / name_patient, 'rb') as f: medscan = pickle.load(f)
medscan = MEDimage.MEDscan(medscan)
medscan = MEDiml.MEDscan(medscan)
except Exception as e:
logging.error(f"\n ERROR LOADING PATIENT {name_patient}:\n {e}")
return None
Expand All @@ -148,7 +148,7 @@ def __compute_radiomics_one_patient(
# Get ROI (region of interest)
logging.info("\n--> Extraction of ROI mask:")
try:
vol_obj_init, roi_obj_init = MEDimage.processing.get_roi_from_indexes(
vol_obj_init, roi_obj_init = MEDiml.processing.get_roi_from_indexes(
medscan,
name_roi=roi_name,
box_string=medscan.params.process.box_string
Expand All @@ -164,7 +164,7 @@ def __compute_radiomics_one_patient(

# Interpolation
# Intensity Mask
vol_obj = MEDimage.processing.interp_volume(
vol_obj = MEDiml.processing.interp_volume(
medscan=medscan,
vol_obj_s=vol_obj_init,
vox_dim=medscan.params.process.scale_non_text,
Expand All @@ -175,7 +175,7 @@ def __compute_radiomics_one_patient(
box_string=medscan.params.process.box_string
)
# Morphological Mask
roi_obj_morph = MEDimage.processing.interp_volume(
roi_obj_morph = MEDiml.processing.interp_volume(
medscan=medscan,
vol_obj_s=roi_obj_init,
vox_dim=medscan.params.process.scale_non_text,
Expand All @@ -189,14 +189,14 @@ def __compute_radiomics_one_patient(
# Re-segmentation
# Intensity mask range re-segmentation
roi_obj_int = deepcopy(roi_obj_morph)
roi_obj_int.data = MEDimage.processing.range_re_seg(
roi_obj_int.data = MEDiml.processing.range_re_seg(
vol=vol_obj.data,
roi=roi_obj_int.data,
im_range=medscan.params.process.im_range
)
# Intensity mask outlier re-segmentation
roi_obj_int.data = np.logical_and(
MEDimage.processing.outlier_re_seg(
MEDiml.processing.outlier_re_seg(
vol=vol_obj.data,
roi=roi_obj_int.data,
outliers=medscan.params.process.outliers
Expand All @@ -216,7 +216,7 @@ def __compute_radiomics_one_patient(

# ROI Extraction :
try:
vol_int_re = MEDimage.processing.roi_extract(
vol_int_re = MEDiml.processing.roi_extract(
vol=vol_obj.data,
roi=roi_obj_int.data
)
Expand All @@ -228,7 +228,7 @@ def __compute_radiomics_one_patient(
try:
if medscan.params.process.user_set_min_value is None:
medscan.params.process.user_set_min_value = np.nanmin(vol_int_re)
vol_obj_all_features = MEDimage.filters.apply_filter(
vol_obj_all_features = MEDiml.filters.apply_filter(
medscan,
vol_int_re,
user_set_min_val=medscan.params.process.user_set_min_value
Expand Down Expand Up @@ -311,7 +311,7 @@ def __compute_radiomics_one_patient(
@ray.remote
def __compute_radiomics_filtered_volume(
self,
medscan: MEDimage.MEDscan,
medscan: MEDiml.MEDscan,
vol_obj,
roi_obj_int,
roi_obj_morph,
Expand All @@ -338,7 +338,7 @@ def __compute_radiomics_filtered_volume(

# Morphological features extraction
try:
morph = MEDimage.biomarkers.morph.extract_all(
morph = MEDiml.biomarkers.morph.extract_all(
vol=vol_obj.data,
mask_int=roi_obj_int.data,
mask_morph=roi_obj_morph.data,
Expand All @@ -351,7 +351,7 @@ def __compute_radiomics_filtered_volume(

# Local intensity features extraction
try:
local_intensity = MEDimage.biomarkers.local_intensity.extract_all(
local_intensity = MEDiml.biomarkers.local_intensity.extract_all(
img_obj=vol_obj.data,
roi_obj=roi_obj_int.data,
res=medscan.params.process.scale_non_text,
Expand All @@ -363,7 +363,7 @@ def __compute_radiomics_filtered_volume(

# statistical features extraction
try:
stats = MEDimage.biomarkers.stats.extract_all(
stats = MEDiml.biomarkers.stats.extract_all(
vol=vol_int_re,
intensity_type=medscan.params.process.intensity_type
)
Expand All @@ -372,7 +372,7 @@ def __compute_radiomics_filtered_volume(
stats = None

# Intensity histogram equalization of the imaging volume
vol_quant_re, _ = MEDimage.processing.discretize(
vol_quant_re, _ = MEDiml.processing.discretize(
vol_re=vol_int_re,
discr_type=medscan.params.process.ih['type'],
n_q=medscan.params.process.ih['val'],
Expand All @@ -381,7 +381,7 @@ def __compute_radiomics_filtered_volume(

# Intensity histogram features extraction
try:
int_hist = MEDimage.biomarkers.intensity_histogram.extract_all(
int_hist = MEDiml.biomarkers.intensity_histogram.extract_all(
vol=vol_quant_re
)
except Exception as e:
Expand All @@ -391,7 +391,7 @@ def __compute_radiomics_filtered_volume(
# Intensity histogram equalization of the imaging volume
if medscan.params.process.ivh and 'type' in medscan.params.process.ivh and 'val' in medscan.params.process.ivh:
if medscan.params.process.ivh['type'] and medscan.params.process.ivh['val']:
vol_quant_re, wd = MEDimage.processing.discretize(
vol_quant_re, wd = MEDiml.processing.discretize(
vol_re=vol_int_re,
discr_type=medscan.params.process.ivh['type'],
n_q=medscan.params.process.ivh['val'],
Expand All @@ -404,7 +404,7 @@ def __compute_radiomics_filtered_volume(

# Intensity volume histogram features extraction
try:
int_vol_hist = MEDimage.biomarkers.int_vol_hist.extract_all(
int_vol_hist = MEDiml.biomarkers.int_vol_hist.extract_all(
medscan=medscan,
vol=vol_quant_re,
vol_int_re=vol_int_re,
Expand Down Expand Up @@ -449,7 +449,7 @@ def __compute_radiomics_filtered_volume(

# Discretisation :
try:
vol_quant_re, _ = MEDimage.processing.discretize(
vol_quant_re, _ = MEDiml.processing.discretize(
vol_re=vol_int_re,
discr_type=medscan.params.process.algo[a],
n_q=medscan.params.process.gray_levels[a][n],
Expand All @@ -461,7 +461,7 @@ def __compute_radiomics_filtered_volume(

# GLCM features extraction
try:
glcm = MEDimage.biomarkers.glcm.extract_all(
glcm = MEDiml.biomarkers.glcm.extract_all(
vol=vol_quant_re,
dist_correction=medscan.params.radiomics.glcm.dist_correction
)
Expand All @@ -471,7 +471,7 @@ def __compute_radiomics_filtered_volume(

# GLRLM features extraction
try:
glrlm = MEDimage.biomarkers.glrlm.extract_all(
glrlm = MEDiml.biomarkers.glrlm.extract_all(
vol=vol_quant_re,
dist_correction=medscan.params.radiomics.glrlm.dist_correction
)
Expand All @@ -481,14 +481,14 @@ def __compute_radiomics_filtered_volume(

# GLSZM features extraction
try:
glszm = MEDimage.biomarkers.glszm.extract_all(vol=vol_quant_re)
glszm = MEDiml.biomarkers.glszm.extract_all(vol=vol_quant_re)
except Exception as e:
logging.error(f'PROBLEM WITH COMPUTATION OF GLSZM FEATURES {e}')
glszm = None

# GLDZM features extraction
try:
gldzm = MEDimage.biomarkers.gldzm.extract_all(
gldzm = MEDiml.biomarkers.gldzm.extract_all(
vol_int=vol_quant_re,
mask_morph=roi_obj_morph.data
)
Expand All @@ -498,7 +498,7 @@ def __compute_radiomics_filtered_volume(

# NGTDM features extraction
try:
ngtdm = MEDimage.biomarkers.ngtdm.extract_all(
ngtdm = MEDiml.biomarkers.ngtdm.extract_all(
vol=vol_quant_re,
dist_correction=medscan.params.radiomics.ngtdm.dist_correction
)
Expand All @@ -508,7 +508,7 @@ def __compute_radiomics_filtered_volume(

# NGLDM features extraction
try:
ngldm = MEDimage.biomarkers.ngldm.extract_all(vol=vol_quant_re)
ngldm = MEDiml.biomarkers.ngldm.extract_all(vol=vol_quant_re)
except Exception as e:
logging.error(f'PROBLEM WITH COMPUTATION OF NGLDM FEATURES {e}')
ngldm = None
Expand Down Expand Up @@ -605,8 +605,8 @@ def __compute_radiomics_tables(
wildcard = '*_' + scan + '(' + roi_type + ')*.json'

# Create radiomics table
radiomics_table_dict = MEDimage.utils.create_radiomics_table(
MEDimage.utils.get_file_paths(self._path_save / f'features({roi_label})', wildcard),
radiomics_table_dict = MEDiml.utils.create_radiomics_table(
MEDiml.utils.get_file_paths(self._path_save / f'features({roi_label})', wildcard),
im_space,
log_file
)
Expand All @@ -617,7 +617,7 @@ def __compute_radiomics_tables(
np.save(save_path, [radiomics_table_dict])

# Create CSV table and Definitions
MEDimage.utils.write_radiomics_csv(save_path)
MEDiml.utils.write_radiomics_csv(save_path)

logging.info(f"DONE\n {time() - start}\n")

Expand Down Expand Up @@ -740,13 +740,13 @@ def __batch_all_tables(self, im_params: Dict):
label = self.roi_type_labels[r]
wildcard = '*' + label + '*.json'
roi_type = self.roi_types[r] + '_' + self.glcm_features[f_idx]
file_paths = MEDimage.utils.get_file_paths(self._path_save / f'features({roi_type})', wildcard)
file_paths = MEDiml.utils.get_file_paths(self._path_save / f'features({roi_type})', wildcard)
n_files = len(file_paths)
scans = [0] * n_files
modalities = [0] * n_files
for f in range(0, n_files):
rad_file_name = file_paths[f].stem
scans[f] = MEDimage.utils.get_scan_name_from_rad_name(rad_file_name)
scans[f] = MEDiml.utils.get_scan_name_from_rad_name(rad_file_name)
modalities[f] = rad_file_name.split('.')[1]
scans = s = (np.unique(np.array(scans))).tolist()
n_scans = len(scans)
Expand All @@ -755,12 +755,12 @@ def __batch_all_tables(self, im_params: Dict):
scan = scans[s]
modality = modalities[s]
wildcard = '*' + scan + '(' + label + ')*.json'
file_paths = MEDimage.utils.get_file_paths(self._path_save / f'features({roi_type})', wildcard)
file_paths = MEDiml.utils.get_file_paths(self._path_save / f'features({roi_type})', wildcard)
n_files = len(file_paths)

# Finding the images spaces for a test file (assuming that all
# files for a given scan and roi_type_label have the same image spaces
radiomics = MEDimage.utils.json_utils.load_json(file_paths[0])
radiomics = MEDiml.utils.json_utils.load_json(file_paths[0])
im_spaces = [key for key in radiomics.keys()]
im_spaces = im_spaces[:-1]
n_im_spaces = len(im_spaces)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading