Skip to content

Commit

Permalink
layer ploting with region works
Browse files Browse the repository at this point in the history
  • Loading branch information
Oli4 committed Oct 5, 2020
1 parent a1fa0bb commit fb67ede
Showing 1 changed file with 48 additions and 13 deletions.
61 changes: 48 additions & 13 deletions eyepy/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,11 @@ def shape(self):

@property
def layers(self):
if "layers" not in self.annotation:
l_shape = np.zeros((max(config.SEG_MAPPING.values()) + 1, self.oct_obj.SizeX))
self.annotation["layers"] = LayerAnnotation(l_shape)
if callable(self.annotation["layers"]):
self.annotation["layers"] = self.annotation["layers"]()
elif "layers" not in self.annotation:
l_shape = np.zeros((max(config.SEG_MAPPING.values()) + 1),
self.oct_obj.SizeX)
self.annotation["layers"] = LayerAnnotation(l_shape)
return self.annotation["layers"]

@property
Expand Down Expand Up @@ -319,8 +318,9 @@ def plot(self, ax=None, layers=None, drusen=False, layers_kwargs=None,
for layer in layers:
color = layers_color[layer]
try:
segmentation = self.layers[layer]
ax.plot(segmentation, color=color, label=layer,
layer_data = self.layers[layer]
layer_data -= region[0].start
ax.plot(layer_data, color=color, label=layer,
**layers_kwargs)
except KeyError:
warnings.warn(f"Layer '{layer}' has no Segmentation",
Expand Down Expand Up @@ -414,7 +414,7 @@ def __getitem__(self, index) -> Bscan:
x = self.bscans[index]
if callable(x):
self.bscans[index] = x()
self.bscans[index].oct_obj = self
self.bscans[index].oct_obj = self
return self.bscans[index]

def __len__(self):
Expand Down Expand Up @@ -473,11 +473,29 @@ def eyepy_id(self):

@property
def shape(self):
return (self.sizeZ, self.SizeX, self.NumBScans)

@property
def SizeX(self):
try:
return (self.sizeZ, self.SizeX, self.NumBScans)
except AttributeError:
return self[0].shape + (len(self),)
return self.meta["SizeX"]
except:
return self[0].scan.shape[1]

@property
def SizeZ(self):
try:
return self.meta["SizeX"]
except:
return self[0].scan.shape[1]

@property
def NumBScans(self):
try:
return self.meta["NumBScans"]
except:
return len(self)

@property
def enface(self):
""" A numpy array holding the OCTs localizer enface if available """
Expand Down Expand Up @@ -591,7 +609,14 @@ def tform_enface_to_oct(self):
@property
def tform_oct_to_enface(self):
return self.tform_enface_to_oct.inverse


@property
def enface_shape(self):
try:
return self.enface.shape
except:
return (self.SizeX, self.SizeX)

def _estimate_enface_to_oct_tform(self):
oct_projection_shape = (self.NumBScans, self.SizeX)
src = np.array(
Expand All @@ -609,7 +634,7 @@ def _estimate_enface_to_oct_tform(self):
self[0].StartY / self.ScaleXSlo, self[0].StartX / self.ScaleYSlo,
self[0].EndY / self.ScaleXSlo, self[0].EndX / self.ScaleYSlo
]).reshape((-1, 2))
except AttributeError():
except AttributeError:
# Map the oct projection to a square area of shape (bscan_width, bscan_width)
warnings.warn(
f"Bscan positions on enface image or the scale of the "
Expand Down Expand Up @@ -643,7 +668,7 @@ 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)

@property
def drusenfinder(self):
Expand Down Expand Up @@ -700,6 +725,16 @@ def plot(self, ax=None, slo=True, drusen=False, bscan_region=False,
# self.plot_quantification(space=space, region=region, ax=ax,
# q_kwargs=q_kwargs)

def plot_layer_distance(self, region=np.s_[...], ax=None, bot_layer="BM", top_layer="RPE", vmin=None, vmax=None):
if ax is None:
ax = plt.gca()

dist = self.layers["BM"] - self.layers["RPE"]
img = transform.warp(dist.astype(float),
self.tform_oct_to_enface,
output_shape=self.enface_shape)
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

0 comments on commit fb67ede

Please sign in to comment.