Skip to content

Commit

Permalink
Merge pull request #32 from MahdiAll99/dev
Browse files Browse the repository at this point in the history
Minor changes and bug fixes
  • Loading branch information
MahdiAll99 authored Sep 23, 2022
2 parents 722565a + 4d7ab27 commit 1ed8180
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 46 deletions.
23 changes: 15 additions & 8 deletions MEDimage/wrangling/DataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def __read_all_dicoms(self) -> None:
# ASSOCIATE ALL VOLUMES TO THEIR MASK
self.__associate_rt_stuct()

def process_all_dicoms(self) -> List[MEDimage]:
def process_all_dicoms(self) -> Union[List[MEDimage], None]:
"""This function reads the DICOM content of all the sub-folder tree of a starting directory defined by
`path_to_dicoms`. It then organizes the data (files throughout the starting directory are associated by
'SeriesInstanceUID') in the MEDimage class including the region of interest (ROI) defined by an
Expand Down Expand Up @@ -408,7 +408,8 @@ def process_all_dicoms(self) -> List[MEDimage]:
self.instances = self.instances[:10]
print('DONE')

return self.instances
if self.instances:
return self.instances

def __read_all_niftis(self) -> None:
"""Reads all files in the initial path and organizes other path to images and roi
Expand Down Expand Up @@ -814,10 +815,11 @@ def __pre_radiomics_checks_dimensions(
df_xy = pd.DataFrame(xy_dim["data"], columns=['data'])
del xy_dim["data"] # no interest in keeping data (we only need statistics)
ax = df_xy.hist(column='data')
min_quant, max_quant= df_xy.quantile(min_percentile), df_xy.quantile(max_percentile)
min_quant, max_quant, average = df_xy.quantile(min_percentile), df_xy.quantile(max_percentile), df_xy.mean()
for x in ax[0]:
x.axvline(min_quant.data, linestyle=':', color='r', label=f"Min Percentile: {float(min_quant):.3f}")
x.axvline(max_quant.data, linestyle=':', color='g', label=f"Max Percentile: {float(max_quant):.3f}")
x.axvline(average.data, linestyle='solid', color='gold', label=f"Average: {float(average.data):.3f}")
x.grid(False)
plt.title(f"Voxels xy-spacing checks for {wildcard}")
plt.legend()
Expand All @@ -827,10 +829,11 @@ def __pre_radiomics_checks_dimensions(
df_z = pd.DataFrame(z_dim["data"], columns=['data'])
del z_dim["data"] # no interest in keeping data (we only need statistics)
ax = df_z.hist(column='data')
min_quant, max_quant= df_z.quantile(min_percentile), df_z.quantile(max_percentile)
min_quant, max_quant, average = df_z.quantile(min_percentile), df_z.quantile(max_percentile), df_z.mean()
for x in ax[0]:
x.axvline(min_quant.data, linestyle=':', color='r', label=f"Min Percentile: {float(min_quant):.3f}")
x.axvline(max_quant.data, linestyle=':', color='g', label=f"Max Percentile: {float(max_quant):.3f}")
x.axvline(average.data, linestyle='solid', color='gold', label=f"Average: {float(average.data):.3f}")
x.grid(False)
plt.title(f"Voxels z-spacing checks for {wildcard}")
plt.legend()
Expand Down Expand Up @@ -1344,21 +1347,23 @@ class zDim:

# Plotting xy-spacing histogram
ax = df_xy.hist(column='xyDim')
min_quant, max_quant= df_xy.quantile(min_percentile), df_xy.quantile(max_percentile)
min_quant, max_quant, average = df_xy.quantile(min_percentile), df_xy.quantile(max_percentile), param.xyDim.data.mean()
for x in ax[0]:
x.axvline(min_quant.xyDim, linestyle=':', color='r', label=f"Min Percentile: {float(min_quant):.3f}")
x.axvline(max_quant.xyDim, linestyle=':', color='g', label=f"Max Percentile: {float(max_quant):.3f}")
x.axvline(average, linestyle='solid', color='gold', label=f"Average: {float(average):.3f}")
x.grid(False)
plt.title(f"MR xy-spacing imaging summary for {wildcard}")
plt.legend()
plt.show()

# Plotting z-spacing histogram
ax = df_z.hist(column='zDim')
min_quant, max_quant = df_z.quantile(min_percentile), df_z.quantile(max_percentile)
min_quant, max_quant, average = df_z.quantile(min_percentile), df_z.quantile(max_percentile), param.zDim.data.mean()
for x in ax[0]:
x.axvline(min_quant.zDim, linestyle=':', color='r', label=f"Min Percentile: {float(min_quant):.3f}")
x.axvline(max_quant.zDim, linestyle=':', color='g', label=f"Max Percentile: {float(max_quant):.3f}")
x.axvline(average, linestyle='solid', color='gold', label=f"Average: {float(average):.3f}")
x.grid(False)
plt.title(f"MR z-spacing imaging summary for {wildcard}")
plt.legend()
Expand Down Expand Up @@ -1550,21 +1555,23 @@ class zDim:

# Plotting xy-spacing histogram
ax = df_xy.hist(column='xyDim')
min_quant, max_quant= df_xy.quantile(min_percentile), df_xy.quantile(max_percentile)
min_quant, max_quant, average = df_xy.quantile(min_percentile), df_xy.quantile(max_percentile), param.xyDim.data.mean()
for x in ax[0]:
x.axvline(min_quant.xyDim, linestyle=':', color='r', label=f"Min Percentile: {float(min_quant):.3f}")
x.axvline(max_quant.xyDim, linestyle=':', color='g', label=f"Max Percentile: {float(max_quant):.3f}")
x.axvline(average, linestyle='solid', color='gold', label=f"Average: {float(average):.3f}")
x.grid(False)
plt.title(f"CT xy-spacing imaging summary for {wildcard}")
plt.legend()
plt.show()

# Plotting z-spacing histogram
ax = df_z.hist(column='zDim')
min_quant, max_quant = df_z.quantile(min_percentile), df_z.quantile(max_percentile)
min_quant, max_quant, average = df_z.quantile(min_percentile), df_z.quantile(max_percentile), param.zDim.data.mean()
for x in ax[0]:
x.axvline(min_quant.zDim, linestyle=':', color='r', label=f"Min Percentile: {float(min_quant):.3f}")
x.axvline(max_quant.zDim, linestyle=':', color='g', label=f"Max Percentile: {float(max_quant):.3f}")
x.axvline(average, linestyle='solid', color='gold', label=f"Average: {float(average):.3f}")
x.grid(False)
plt.title(f"CT z-spacing imaging summary for {wildcard}")
plt.legend()
Expand Down
6 changes: 3 additions & 3 deletions MEDimage/wrangling/ProcessDICOM.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def __get_dicom_scan_orientation(self, dicom_header: List[pydicom.dataset.FileDa
image_patient_positions_y = [dicom_header[i].ImagePositionPatient[1] for i in range(n_slices)]
image_patient_positions_z = [dicom_header[i].ImagePositionPatient[2] for i in range(n_slices)]
dist = [
max(np.abs(np.diff(image_patient_positions_x))),
max(np.abs(np.diff(image_patient_positions_y))),
max(np.abs(np.diff(image_patient_positions_z)))
np.median(np.abs(np.diff(image_patient_positions_x))),
np.median(np.abs(np.diff(image_patient_positions_y))),
np.median(np.abs(np.diff(image_patient_positions_z)))
]
index = dist.index(max(dist))
if index == 0:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ For more installation options (conda, poetry...) check out the [installation doc
We used sphinx to create the documentation for this project and you check it out in this [link](https://medimage.readthedocs.io/en/latest/). But you can generate and host it locally by compiling the documentation source code using:

```
cd docs
make clean
make html
```
Expand Down
7 changes: 6 additions & 1 deletion docs/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ Download dataset
In all the tutorials, an open-access dataset will be used. It consists of medical images for different type of cancers (Glioma, sarcoma...)
and with different imaging modalities (MR, CT and PET). This dataset has been pre-processed in order to be compliant with the package norms.

A script is made available to download the dataset and organize it in your local workspace, just run the following command in your terminal
A script is made available to download the dataset (~3.2 GB) and organize it in your local workspace, just run the following command in your terminal
from the package parent folder ::
python scripts/download_data.py
.. note::
Since the dataset is large, there are available options to download only a subset of the data. For more information, run the following command in your terminal ::
python scripts/download_data.py --help

CSV file
--------
Expand Down
Loading

0 comments on commit 1ed8180

Please sign in to comment.