Skip to content

Commit

Permalink
Added per-patient pixel (voxel) distribution for different regions
Browse files Browse the repository at this point in the history
  • Loading branch information
MrinalJain17 committed Oct 8, 2020
1 parent d30a69f commit e0505dc
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 223 deletions.
245 changes: 245 additions & 0 deletions notebooks/miccai_patient_exploration.ipynb

Large diffs are not rendered by default.

219 changes: 0 additions & 219 deletions notebooks/sample.ipynb

This file was deleted.

13 changes: 9 additions & 4 deletions utils/miccai.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def __init__(self, patient_dir: str):
self.meta_data = self.get_meta_data()

self._image = Volume(self.meta_data["image"])
# self._landmarks = None
self._structures = self.load_structures()
self._landmarks = None

@property
def image(self) -> Volume:
Expand All @@ -83,9 +83,9 @@ def structures(self) -> AttrDict:
def num_slides(self) -> int:
return self.image.data.shape[1]

# @property
# def landmarks(self):
# return self._landmarks
@property
def landmarks(self):
return self._landmarks

@property
def patient_dir(self) -> str:
Expand All @@ -102,6 +102,11 @@ def load_structures(self) -> AttrDict:
return temp

def combine_structures(self, structure_list: list) -> np.ndarray:
"""
This is used as a workaround for overlaying multiple segmentation masks
(each corresponding to different region) over a slide. The "correct" way
can be quite complicated, and is not worth the time for now.
"""
assert len(structure_list) > 1, "A minimum of 2 structures are required"
structure_arrays = []

Expand Down
25 changes: 25 additions & 0 deletions utils/visualize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ipywidgets as widgets
import matplotlib.pyplot as plt
import seaborn as sns
from ipywidgets import fixed, interact

from .miccai import STRUCTURES, Patient
Expand Down Expand Up @@ -33,6 +34,30 @@ def plot_slide(patient: Patient, index=0, region=None):
return axes


def plot_region_distribution(patient: Patient, exclude=None, ax=None):
voxel_dict = {}
if exclude is None:
exclude = []
elif isinstance(exclude, str):
exclude = [exclude]

for structure in STRUCTURES:
if structure not in exclude:
region_volume = patient.structures[structure]
if region_volume is not None:
voxel_dict[structure] = patient.image.as_numpy()[
region_volume.as_numpy() == 1
]

ax = sns.boxplot(
data=list(voxel_dict.values()), showmeans=True, showfliers=False, ax=ax
)
ax.set_xticklabels(voxel_dict.keys(), rotation=45)
ax.set_ylabel("Hounsfield Units (HU)")

return ax


def notebook_interact(patient: Patient):
return interact(
plot_slide,
Expand Down

0 comments on commit e0505dc

Please sign in to comment.