Skip to content

Commit

Permalink
guaranteeing that crops can never have zero pixels in any dim
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Greenberg committed Jan 29, 2020
1 parent 5e105ce commit 41ab617
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions multivitamin/data/response/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def p0p1_from_bbox_contour(contour, w=1, h=1, dtype=int):

def compute_box_area(contour):
"""Function to compute the spatial fraction based on the contour
Args:
contour (List[Point]): contour
Returns:
float: fraction
"""
Expand All @@ -78,11 +78,11 @@ def compute_box_area(contour):

def crop_image_from_bbox_contour(image, contour):
"""Crop an image given a bounding box contour
Args:
Args:
image (np.array): image
contour (dict[float]): points of a bounding box countour
Returns:
np.array: image
"""
Expand All @@ -92,6 +92,13 @@ def crop_image_from_bbox_contour(image, contour):
h = image.shape[0]
w = image.shape[1]
(x0, y0), (x1, y1) = p0p1_from_bbox_contour(contour, w=w, h=h)

if x1 - x0 < 1:
x1 = x0 + 1

if y1 - y0 < 1:
y1 = y0 + 1

return image[y0:y1, x0:x1]


Expand All @@ -100,7 +107,7 @@ def round_float(val):
Args:
val (float): input value
Returns:
float: rounded float value
"""
Expand All @@ -112,7 +119,7 @@ def round_float_to_str(val):
Args:
val (float): input value
Returns:
float: rounded float value
"""
Expand All @@ -139,7 +146,7 @@ def round_all_pts_in_contour_to_str(contour):
Args:
contour (list): list of dicts with keys x, y
Returns:
list: of dicts of points
"""
Expand All @@ -157,7 +164,7 @@ def points_equal(val0, val1):
Args:
val0 (float): first value
val1 (float): second value
Returns:
bool: equality
"""
Expand All @@ -170,7 +177,7 @@ def times_equal(val0, val1, eps=config.TIME_EPS):
Args:
val0 (float): first value
val1 (float): second value
Returns:
bool: equality
"""
Expand Down

0 comments on commit 41ab617

Please sign in to comment.