|
@@ -1,6 +1,7 @@
|
|
|
import numpy as np
|
|
|
|
|
|
from matplotlib.patches import Rectangle
|
|
|
+from functools import partial
|
|
|
|
|
|
from nabirds import utils
|
|
|
from .base import BasePart
|
|
@@ -20,32 +21,41 @@ class LocationPart(BasePart):
|
|
|
def as_annotation(self):
|
|
|
return np.array([self._id, self.x, self.y, self.is_visible])
|
|
|
|
|
|
- def crop(self, image, ratio=None, padding_mode="edge", *args, **kwargs):
|
|
|
+ def _generic_op(self, image, ratio, op):
|
|
|
ratio = ratio or self._ratio
|
|
|
- _h, _w, c = utils.dimensions(image)
|
|
|
+ _h, _w, _ = utils.dimensions(image)
|
|
|
w, h = int(_w * ratio), int(_h * ratio)
|
|
|
- return super(LocationPart, self).crop(image, w, h,
|
|
|
+ x, y = self.xy
|
|
|
+
|
|
|
+ return op(image, x, y, w, h)
|
|
|
+
|
|
|
+ def crop(self, image, ratio=None, padding_mode="edge", *args, **kwargs):
|
|
|
+
|
|
|
+ def op(im, x, y, w, h):
|
|
|
+ return super(LocationPart, self).crop(im, w, h,
|
|
|
padding_mode, is_location=True)
|
|
|
|
|
|
+ return self._generic_op(image, ratio, op)
|
|
|
+
|
|
|
def reveal(self, im, ratio=None, *args, **kwargs):
|
|
|
- _h, _w, c = utils.dimensions(im)
|
|
|
- w, h = int(_w * ratio), int(_h * ratio)
|
|
|
- x,y = self.xy
|
|
|
- x, y = max(x - w // 2, 0), max(y - h // 2, 0)
|
|
|
- return x, y, im[y:y+h, x:x+w]
|
|
|
|
|
|
- def plot(self, im, ax, ratio, fill=False, linestyle="--", **kwargs):
|
|
|
+ def op(im, x, y, w, h):
|
|
|
+ x, y = max(x - w // 2, 0), max(y - h // 2, 0)
|
|
|
+ return x, y, im[y:y+h, x:x+w]
|
|
|
+
|
|
|
+ return self._generic_op(im, ratio, op)
|
|
|
+
|
|
|
+ def plot(self, im, ax, ratio=None, fill=False, linestyle="--", **kwargs):
|
|
|
if not self.is_visible: return
|
|
|
- x, y = self.xy
|
|
|
- _h, _w, c = utils.dimensions(im)
|
|
|
- w, h = int(_w * ratio), int(_h * ratio)
|
|
|
- ax.add_patch(Rectangle(
|
|
|
- (x-w//2, y-h//2), w, h,
|
|
|
- fill=fill, linestyle=linestyle,
|
|
|
- **kwargs
|
|
|
- ))
|
|
|
|
|
|
- ax.scatter(*self.middle, marker="x", color="white", alpha=0.8)
|
|
|
+ def op(im, x, y, w, h):
|
|
|
+ ax.add_patch(Rectangle(
|
|
|
+ (x-w//2, y-h//2), w, h,
|
|
|
+ fill=fill, linestyle=linestyle,
|
|
|
+ **kwargs))
|
|
|
+
|
|
|
+ ax.scatter(*self.middle, marker="x", color="white", alpha=0.8)
|
|
|
+ return self._generic_op(im, ratio, op)
|
|
|
|
|
|
|
|
|
@property
|