Skip to content

Commit

Permalink
feat: check valid bbox
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-grim authored Jan 15, 2025
1 parent d44723f commit b6a762e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/aind_exaspim_soma_detection/utils/img_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ def get_patch(img, voxel, shape, from_center=True):
Patch extracted from the given image.
"""
# Get image patch coordiantes
start, end = get_start_end(voxel, shape, from_center=from_center)
return img[0, 0, start[0]: end[0], start[1]: end[1], start[2]: end[2]]
valid_start = any([s < 0 for s in start])
valid_end = any([e > img.shape[i + 2] for i, e in enumerate(end)])

# Get image patch
if valid_start and valid_end:
return img[0, 0, start[0]: end[0], start[1]: end[1], start[2]: end[2]]
else:
return np.zeros(shape)


def sliding_window_coords_3d(img, window_shape, overlap):
Expand Down
30 changes: 30 additions & 0 deletions src/aind_exaspim_soma_detection/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,33 @@ def sample_once(my_container):
"""
return sample(my_container, 1)[0]


def time_writer(t, unit="seconds"):
"""
Converts a runtime "t" to a larger unit of time if applicable.
Parameters
----------
t : float
Runtime.
unit : str, optional
Unit of time that "t" is expressed in.
Returns
-------
float
Runtime
str
Unit of time.
"""
assert unit in ["seconds", "minutes", "hours"]
upd_unit = {"seconds": "minutes", "minutes": "hours"}
if t < 60 or unit == "hours":
return t, unit
else:
t /= 60
unit = upd_unit[unit]
t, unit = time_writer(t, unit=unit)
return t, unit

0 comments on commit b6a762e

Please sign in to comment.