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
2 changes: 1 addition & 1 deletion MEDiml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logging.getLogger(__name__).addHandler(stream_handler)

__author__ = "MEDomicsLab consortium"
__version__ = "0.9.9"
__version__ = "0.9.10"
__copyright__ = "Copyright (C) MEDomicsLab consortium"
__license__ = "GNU General Public License 3.0"
__maintainer__ = "MAHDI AIT LHAJ LOUTFI"
Expand Down
53 changes: 40 additions & 13 deletions MEDiml/wrangling/DataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,7 @@ def __associate_roi_to_image(
Returns:
MEDscan: Returns a MEDscan instance with updated roi attributes.
"""
image_file = Path(image_file)
roi_index = 0

if not path_roi_data:
if not self.paths._path_to_niftis:
raise ValueError("The path to the niftis is not defined")
else:
path_roi_data = self.paths._path_to_niftis

for file in path_roi_data.glob('*.nii.gz'):
_id = image_file.name.split("(")[0] # id is PatientID__ImagingScanName
def load_mask(_id, file, medscan):
# Load the patient's ROI nifti files:
if file.name.startswith(_id) and 'ROI' in file.name.split("."):
roi = nib.load(file)
Expand All @@ -452,8 +442,27 @@ def __associate_roi_to_image(
name_set = file.name[file.name.find("_") + 2 : file.name.find("(")]
medscan.data.ROI.update_indexes(key=roi_index, indexes=np.nonzero(roi_data.flatten()))
medscan.data.ROI.update_name_set(key=roi_index, name_set=name_set)
medscan.data.ROI.update_roi_name(key=roi_index, roi_name=roi_name)
medscan.data.ROI.update_roi_name(key=roi_index, roi_name=roi_name)
else:
raise ValueError(f"The ROI file for patient ID: {_id} "
f"was not found in the given path: {file} or was not correctly named.")

image_file = Path(image_file)
roi_index = 0
if not path_roi_data:
if not self.paths._path_to_niftis:
raise ValueError("The path to the niftis is not defined")
else:
path_roi_data = self.paths._path_to_niftis

for file in self.__nifti.stack_path_roi:
_id = image_file.name.split("(")[0] if ("(") in image_file.name else image_file.name # id is PatientID__ImagingScanName
load_mask(_id, file, medscan)
roi_index += 1
else:
_id = image_file.name.split("(")[0] if ("(") in image_file.name else image_file.name # id is PatientID__ImagingScanName
load_mask(_id, path_roi_data, medscan)

return medscan

def __associate_spatialRef(self, nifti_file: Union[Path, str], medscan: MEDscan) -> MEDscan:
Expand Down Expand Up @@ -567,7 +576,7 @@ def process_all_niftis(self) -> List[MEDscan]:
medscan = MEDscan()
medscan.patientID = os.path.basename(file).split("_")[0]
medscan.type = os.path.basename(file).split(".")[-3]
medscan.series_description = file.name[file.name.find('__') + 2: file.name.find('(')]
medscan.series_description = file.name[file.name.find('__') + 2: file.name.find('(')] if '__' in file.name else ""
medscan.format = "nifti"
medscan.data.set_orientation(orientation="Axial")
medscan.data.set_patient_position(patient_position="HFS")
Expand Down Expand Up @@ -625,6 +634,24 @@ def process_all_niftis(self) -> List[MEDscan]:
if list_instances:
return list_instances

def process_one_nifti(self, path_image: Union[Path, str], path_mask: Union[Path, str]) -> MEDscan:
"""Processes one NIfTI file to create a MEDscan class instance.

Args:
nifti_file (Union[Path, str]): Path to the NIfTI file.
path_data (Union[Path, str]): Path to the data.

Returns:
MEDscan: MEDscan class instance.
"""
medscan = self.__process_one_nifti(path_image, path_mask)

# SAVE MEDscan INSTANCE
if self.save and self.paths._path_save:
save_MEDscan(medscan, self.paths._path_save)

return medscan

def update_from_csv(self, path_csv: Union[str, Path] = None) -> None:
"""Updates the class from a given CSV and summarizes the processed scans again according to it.

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<img src="https://github.com/MEDomicsLab/MEDiml/blob/main/docs/figures/MEDimlLogo150.png?raw=true" style="width:150px;"/>

[![PyPI - Python Version](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10-blue)](https://www.python.org/downloads/release/python-380/)
[![PyPI - version](https://img.shields.io/badge/pypi-v0.9.8-blue)](https://pypi.org/project/medimage-pkg/)
[![PyPI - version](https://img.shields.io/badge/pypi-v0.9.10-blue)](https://pypi.org/project/medimage-pkg/)
[![Continuous Integration](https://github.com/MEDomicsLab/MEDiml/actions/workflows/python-app.yml/badge.svg)](https://github.com/MEDomicsLab/MEDiml/actions/workflows/python-app.yml)
[![Documentation Status](https://readthedocs.org/projects/mediml/badge/?version=latest)](https://mediml.readthedocs.io/en/latest/?badge=latest)
[![License: GPL-3](https://img.shields.io/badge/license-GPLv3-blue)](LICENSE)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/tutorial/DataManager-Tutorial.ipynb)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/tutorial/DataManager-Tutorial.ipynb)

</div>

Expand All @@ -27,7 +27,7 @@
## 1. Introduction
MEDiml is an open-source Python package that can be used for processing multi-modal medical images (MRI, CT or PET) and for extracting their radiomic features. This package is meant to facilitate the processing of medical images and the subsequent computation of all types of radiomic features while maintaining the reproducibility of analyses. This package has been standardized with the [IBSI](https://theibsi.github.io/) norms.

![MEDiml overview](https://raw.githubusercontent.com/MahdiAll99/MEDimage/main/docs/figures/pakcage-overview.png)
![MEDiml overview](https://raw.githubusercontent.com/MEDomicsLab/MEDiml/main/docs/figures/pakcage-overview.png)


## 2. Installation
Expand Down Expand Up @@ -107,14 +107,14 @@ The image biomarker standardization initiative ([IBSI](https://theibsi.github.io
- ### IBSI Chapter 1
[The IBSI chapter 1](https://theibsi.github.io/ibsi1/) is dedicated to the standardization of commonly used radiomic features. It was initiated in September 2016 and reached completion in March 2020. We have created two [jupyter notebooks](https://github.com/MEDomicsLab/MEDiml/tree/main/notebooks/ibsi) for each phase of the chapter and made them available for the users to run the IBSI tests for themselves. The tests can also be explored in interactive Colab notebooks that are directly accessible here:

- **Phase 1**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/ibsi/ibsi1p1.ipynb)
- **Phase 2**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/ibsi/ibsi1p2.ipynb)
- **Phase 1**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/ibsi/ibsi1p1.ipynb)
- **Phase 2**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/ibsi/ibsi1p2.ipynb)

- ### IBSI Chapter 2
[The IBSI chapter 2](https://theibsi.github.io/ibsi2/) was launched in June 2020 and reached completion in February 2024. It is dedicated to the standardization of commonly used imaging filters in radiomic studies. We have created two [jupyter notebooks](https://github.com/MEDomicsLab/MEDiml/tree/main/notebooks/ibsi) for each phase of the chapter and made them available for the users to run the IBSI tests for themselves and validate image filtering and image biomarker calculations from filter response maps. The tests can also be explored in interactive Colab notebooks that are directly accessible here:

- **Phase 1**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/ibsi/ibsi2p1.ipynb)
- **Phase 2**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/ibsi/ibsi2p2.ipynb)
- **Phase 1**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/ibsi/ibsi2p1.ipynb)
- **Phase 2**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/ibsi/ibsi2p2.ipynb)

Our team at *UdeS* (a.k.a. Université de Sherbrooke) has already submitted the benchmarked values to the [IBSI uploading website](https://ibsi.radiomics.hevs.ch/).

Expand Down
Loading