Skip to content

Commit

Permalink
Now body cut should run faster
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCappelletti94 committed Jun 19, 2020
1 parent 03e76c5 commit 95d7d6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions covidxpert/body_cut/body_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ def get_complete_body_mask(image: np.ndarray, width=256) -> np.ndarray:
)


def get_bounding_box(mask, step=20) -> float:
def get_bounding_box(mask: np.ndarray, step: int = None) -> float:
best_score = 0
best_y = 0
height = mask.shape[0]
if step is None:
step = height//40
for lower_y in range(step, height, step):
rectangle = np.zeros_like(mask, dtype=np.bool_)
rectangle[height-lower_y:height] = True
Expand All @@ -53,7 +55,7 @@ def get_body_cut(image: np.ndarray, rotated: np.ndarray, angle: float, simmetry_
"""Return the body cut for given image.
TODO! Update docstring
Parameters
--------------------------------------
image: np.ndarray,
Expand Down Expand Up @@ -88,4 +90,4 @@ def get_body_cut(image: np.ndarray, rotated: np.ndarray, angle: float, simmetry_
if others is None:
return result

return result, [other[body_slice] for other in others]
return (*result, [other[body_slice] for other in others])
10 changes: 5 additions & 5 deletions covidxpert/counter_rotate/counter_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def counter_rotate(
angle1, spine_x = get_rectangle_based_rotation(spine)
angle2 = get_lines_based_rotation(spine)

blurred0 = cv2.blur(thumb, (21, 21)) # pylint: disable=no-member
blurred0 = cv2.blur(thumb, (21, 21)) # pylint: disable=no-member
blurred1 = rotate_image(blurred0, angle1)
blurred2 = rotate_image(blurred0, angle2)

Expand All @@ -68,12 +68,12 @@ def counter_rotate(
angle0, angle1, angle2
][best_rotation]

result = rotate_image(image, best_angle)
result = rotate_image(image, best_angle), best_angle, spine_x

if others is None:
return result, best_angle, spine_x
return result

return result, best_angle, spine_x, [
return (*result, [
rotate_image(other, best_angle)
for other in others
]
])

0 comments on commit 95d7d6b

Please sign in to comment.