summaryrefslogtreecommitdiff
path: root/megapixels/app/models
diff options
context:
space:
mode:
authoradamhrv <adam@ahprojects.com>2019-01-15 00:17:56 +0100
committeradamhrv <adam@ahprojects.com>2019-01-15 00:17:56 +0100
commit7c42c8f62b58d6d6c4e1c6332ccc89c7cbc26a29 (patch)
tree47042cb9b23afa6a5b3587a2d8afa2e04297e409 /megapixels/app/models
parent5d87daada7980888b36304619913da2ca8e83a8e (diff)
add expand
Diffstat (limited to 'megapixels/app/models')
-rw-r--r--megapixels/app/models/bbox.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/megapixels/app/models/bbox.py b/megapixels/app/models/bbox.py
index 40874691..f1216698 100644
--- a/megapixels/app/models/bbox.py
+++ b/megapixels/app/models/bbox.py
@@ -130,6 +130,22 @@ class BBox:
# -----------------------------------------------------------------
# Modify
+ def expand(self, per):
+ """Expands BBox by percentage
+ :param per: (float) percentage to expand 0.0 - 1.0
+ :param dim: (int, int) image width, height
+ :returns (BBox) expanded
+ """
+ # expand
+ dw, dh = [(self._width * per), (self._height * per)]
+ r = list(np.array(self._rect) + np.array([-dw, -dh, dw, dh]))
+ # threshold expanded rectangle
+ r[0] = max(r[0], 0.0)
+ r[1] = max(r[1], 0.0)
+ r[2] = min(r[2], 1.0)
+ r[3] = min(r[3], 1.0)
+ return BBox(*r)
+
def expand_dim(self, amt, bounds):
"""Expands BBox within dim
:param box: (tuple) left, top, right, bottom