Skip to content

Commit

Permalink
Option to reverse the offset/size array orders when getting blobs in …
Browse files Browse the repository at this point in the history
…an ROI

Allow the `offset` and `size` parameters to be given in x,y,z or z,y,x order that the function will support arrays given for either ROIs or sub-images. Continue to use x,y,z as default since the current convent for ROI parameters has been to use x,y,z ordering, but this change helps prepare for changing the order to z,y,x.
  • Loading branch information
yoda-vid committed Mar 15, 2020
1 parent 37737b2 commit e51d6dd
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions magmap/cv/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def remove_close_blobs_within_sorted_array(blobs, tol):
#print("blobs without close duplicates:\n{}".format(blobs_all))
return blobs_all

def get_blobs_in_roi(blobs, offset, size, padding=(0, 0, 0)):
def get_blobs_in_roi(blobs, offset, size, padding=(0, 0, 0), reverse=True):
"""Get blobs within an ROI based on offset and size.
Note that dimensions are in x,y,z for natural ordering but may
Expand All @@ -668,21 +668,28 @@ def get_blobs_in_roi(blobs, offset, size, padding=(0, 0, 0)):
Args:
blobs: The blobs to retrieve, given as 2D array of
``[n, [z, row, column, radius, ...]]``.
offset: Offset coordinates in x,y,z.
offset: Offset coordinates in .
size: Size of ROI in x,y,z.
padding: Additional padding outside the ROI to include.
reverse (bool): True to reverse the order of ``offset`` and ``size``,
assuming that they are in x,y,z rather than z,y,x order.
Defaults to True for backward compatibility with the ROI
convention used here.
Returns:
Tuple of blobs within the ROI and the mask used to retrieve
these blobs.
"""
if reverse:
offset = offset[::-1]
size = size[::-1]
mask = np.all([
blobs[:, 0] >= offset[2] - padding[2],
blobs[:, 0] < offset[2] + size[2] + padding[2],
blobs[:, 0] >= offset[0] - padding[0],
blobs[:, 0] < offset[0] + size[0] + padding[0],
blobs[:, 1] >= offset[1] - padding[1],
blobs[:, 1] < offset[1] + size[1] + padding[1],
blobs[:, 2] >= offset[0] - padding[0],
blobs[:, 2] < offset[0] + size[0] + padding[0]], axis=0)
blobs[:, 2] >= offset[2] - padding[2],
blobs[:, 2] < offset[2] + size[2] + padding[2]], axis=0)
segs_all = blobs[mask]
return segs_all, mask

Expand Down

0 comments on commit e51d6dd

Please sign in to comment.