Skip to content

Commit

Permalink
Severall small fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Oli4 committed Oct 8, 2020
1 parent cbae8db commit 161ecb4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
46 changes: 30 additions & 16 deletions eyepy/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ def plot(self, ax=None, layers=None, drusen=False, layers_kwargs=None,
layers_color=None, annotation_only=False, region=np.s_[...]):
""" Plot B-Scan with segmented Layers """
if ax is None:
fig, ax = plt.subplots(1, 1)
else:
fig = plt.gcf()
ax = plt.gca()

if layers is None:
layers = []
Expand All @@ -320,7 +318,8 @@ def plot(self, ax=None, layers=None, drusen=False, layers_kwargs=None,
color = layers_color[layer]
try:
layer_data = self.layers[layer]
layer_data -= region[0].start
if region[0].start is not None:
layer_data -= region[0].start
ax.plot(layer_data, color=color, label=layer,
**layers_kwargs)
except KeyError:
Expand Down Expand Up @@ -531,10 +530,13 @@ def layers_raw(self):
Layers for all B-Scans are stacked such that we get a volume L x B x W
where L are different Layers, B are the B-Scans and W is the Width of
the B-Scans.
A flip on the B-Scan axis is needed to locate the first B-Scan at the
bottom of the height map.
"""
if self._layers_raw is None:
self._layers_raw = np.stack([x.layers.data
for x in self], axis=1)
self._layers_raw = np.flip(np.stack([x.layers.data
for x in self], axis=1), axis=1)
return self._layers_raw

@property
Expand All @@ -556,6 +558,8 @@ def meta(self):
The object can be printed to see all available meta data.
"""
if self._meta is None:
raise AttributeError("This volume has no meta data")
return self._meta

@property
Expand Down Expand Up @@ -628,6 +632,12 @@ def _estimate_enface_to_oct_tform(self):
0, 0, # Bottom left
0, oct_projection_shape[1] - 1 # Bottom right
]).reshape((-1, 2))
src = np.array(
[0, 0, # Top left
0, oct_projection_shape[1] - 1, # Top right
oct_projection_shape[0] - 1, 0, # Bottom left
oct_projection_shape[0] - 1, oct_projection_shape[1] - 1 # Bottom right
]).reshape((-1, 2))

try:
# Try to map the oct projection to the enface image
Expand All @@ -646,10 +656,10 @@ def _estimate_enface_to_oct_tform(self):
UserWarning)
b_width = self[0].shape[1]
dst = np.array(
[b_width - 1, 0, # Top left
b_width - 1, b_width - 1, # Top right
0, 0, # Bottom left
0, b_width - 1 # Bottom right
[0, 0, # Top left
0, b_width - 1, # Top right
b_width - 1, 0, # Bottom left
b_width - 1, b_width - 1 # Bottom right
]).reshape((-1, 2))

src = src[:, [1, 0]]
Expand All @@ -664,14 +674,18 @@ def _estimate_enface_to_oct_tform(self):

@property
def drusen_projection(self):
return np.swapaxes(np.sum(self.drusen, axis=0), 0, 1)
# Sum the all B-Scans along their first axis (B-Scan height)
# Swap axis such that the volume depth becomes the projections height not width
# We want the first B-Scan to be located at the bottom hence flip along axis 0
return np.flip(np.swapaxes(np.sum(self.drusen, axis=0), 0, 1), axis=0)

@property
def drusen_enface(self):
""" Drusen projection warped into the enface space """
return transform.warp(self.drusen_projection.astype(float),
self.tform_oct_to_enface,
output_shape=self.enface_shape)
output_shape=self.enface_shape,
order=0)

@property
def drusenfinder(self):
Expand All @@ -688,7 +702,7 @@ def drusenfinder(self, drusenfinder):
self._drusenfinder = drusenfinder

def plot(self, ax=None, enface=True, drusen=False, bscan_region=False,
bscan_positions=None, masks=False, region=np.s_[...], alpha=1,
bscan_positions=None, masks=False, region=np.s_[...],
drusen_kwargs=None):
"""
Expand Down Expand Up @@ -716,7 +730,7 @@ def plot(self, ax=None, enface=True, drusen=False, bscan_region=False,
if drusen:
if drusen_kwargs is None:
drusen_kwargs = {}
self.plot_drusen(ax=ax, region=region, alpha=alpha, **drusen_kwargs)
self.plot_drusen(ax=ax, region=region, **drusen_kwargs)
if bscan_positions is not None:
self.plot_bscan_positions(ax=ax, bscan_positions=bscan_positions,
region=region,
Expand All @@ -731,7 +745,7 @@ def plot(self, ax=None, enface=True, drusen=False, bscan_region=False,
# self.plot_quantification(space=space, region=region, ax=ax,
# q_kwargs=q_kwargs)

def plot_bscan_ticks(ax=None):
def plot_bscan_ticks(self, ax=None):
if ax is None:
ax = plt.gca()
ax.yticks()
Expand All @@ -743,7 +757,7 @@ def plot_layer_distance(self, region=np.s_[...], ax=None, bot_layer="BM", top_la
dist = self.layers["BM"] - self.layers["RPE"]
img = transform.warp(dist.astype(float),
self.tform_oct_to_enface,
output_shape=self.enface_shape)
output_shape=self.enface_shape, order=0)
ax.imshow(img[region], cmap="gray", vmin=vmin, vmax=vmax)

def plot_masks(self, region=np.s_[...], ax=None, color="r", linewidth=0.5):
Expand Down
5 changes: 3 additions & 2 deletions eyepy/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
SAVE_DRUSEN = False

# Line Style for Layers in B-Scan
layers_kwargs = {"linewidth": 0.3, "linestyle": "-"}
layers_kwargs = {"linewidth": 1, "linestyle": "-"}

# Line Style for B-Scan positions on Slo
line_kwargs = {"linewidth": 0.3, "linestyle": "-"}

# Colors for different Layers
color_palette = sns.color_palette("hls", 17)
x = sns.color_palette("husl", 17)
color_palette = sns.color_palette(x[::3] + x[1::3] + x[2::3])
layers_color = {key: color_palette[value] for key, value in SEG_MAPPING.items()}
16 changes: 7 additions & 9 deletions eyepy/core/drusen.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,14 @@ def filter_by_depth(drusen_map, minimum_depth=2):
return drusen_map
# get array where connected components get same label
connected_component_array, num_drusen = ndimage.label(drusen_map)
drusen_positions = ndimage.find_objects(connected_component_array)
# Go through each component, sum it along 2 axis and check max depth against threshold
for i, label in enumerate(range(1, num_drusen+1)):
druse = connected_component_array[drusen_positions[i]]
druse[druse == label] = 1
druse[druse != label] = 0
drusen_depth = np.sum(druse, axis=2)
if np.max(drusen_depth) <= minimum_depth:
# Remove drusen for this label
filtered_drusen[connected_component_array == label] = False
max_depths = np.zeros_like(connected_component_array)
for label, drusen_pos in enumerate(ndimage.find_objects(connected_component_array)):
component_sub_vol = connected_component_array[drusen_pos]
component_max_depth = np.max(np.sum(component_sub_vol==label+1, axis=2))
component_sub_vol[component_sub_vol==label+1] = component_max_depth
max_depths[drusen_pos] = component_sub_vol
filtered_drusen[max_depths <= minimum_depth] = False
return filtered_drusen


Expand Down

0 comments on commit 161ecb4

Please sign in to comment.